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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (746) hide show
  1. package/README.md +528 -161
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +12 -6
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/board-events.d.ts +54 -0
  6. package/dist/boards/board-events.d.ts.map +1 -0
  7. package/dist/boards/board-events.js +87 -0
  8. package/dist/boards/board-events.js.map +1 -0
  9. package/dist/boards/board-writes.d.ts +86 -0
  10. package/dist/boards/board-writes.d.ts.map +1 -0
  11. package/dist/boards/board-writes.js +266 -0
  12. package/dist/boards/board-writes.js.map +1 -0
  13. package/dist/boards/card-facts.d.ts +3 -1
  14. package/dist/boards/card-facts.d.ts.map +1 -1
  15. package/dist/boards/card-facts.js +30 -4
  16. package/dist/boards/card-facts.js.map +1 -1
  17. package/dist/boards/default-board.d.ts +7 -0
  18. package/dist/boards/default-board.d.ts.map +1 -0
  19. package/dist/boards/default-board.js +10 -0
  20. package/dist/boards/default-board.js.map +1 -0
  21. package/dist/boards/define-board.d.ts +56 -23
  22. package/dist/boards/define-board.d.ts.map +1 -1
  23. package/dist/boards/define-board.js +89 -45
  24. package/dist/boards/define-board.js.map +1 -1
  25. package/dist/boards/index.d.ts +6 -9
  26. package/dist/boards/index.d.ts.map +1 -1
  27. package/dist/boards/index.js +6 -20
  28. package/dist/boards/intake-routing.d.ts +55 -11
  29. package/dist/boards/intake-routing.d.ts.map +1 -1
  30. package/dist/boards/intake-routing.js +109 -19
  31. package/dist/boards/intake-routing.js.map +1 -1
  32. package/dist/boards/legacy-plan-role.d.ts.map +1 -1
  33. package/dist/boards/legacy-plan-role.js +14 -5
  34. package/dist/boards/legacy-plan-role.js.map +1 -1
  35. package/dist/boards/phase-automation.d.ts +7 -0
  36. package/dist/boards/phase-automation.d.ts.map +1 -1
  37. package/dist/boards/phase-automation.js +19 -3
  38. package/dist/boards/phase-automation.js.map +1 -1
  39. package/dist/boards/phase-runner.d.ts +18 -10
  40. package/dist/boards/phase-runner.d.ts.map +1 -1
  41. package/dist/boards/phase-runner.js +39 -34
  42. package/dist/boards/phase-runner.js.map +1 -1
  43. package/dist/boards/project-boards.d.ts +65 -8
  44. package/dist/boards/project-boards.d.ts.map +1 -1
  45. package/dist/boards/project-boards.js +217 -26
  46. package/dist/boards/project-boards.js.map +1 -1
  47. package/dist/boards/registry.d.ts +7 -1
  48. package/dist/boards/registry.d.ts.map +1 -1
  49. package/dist/boards/registry.js +19 -4
  50. package/dist/boards/registry.js.map +1 -1
  51. package/dist/boards/relocate.d.ts +1 -1
  52. package/dist/boards/relocate.d.ts.map +1 -1
  53. package/dist/boards/relocate.js +3 -2
  54. package/dist/boards/relocate.js.map +1 -1
  55. package/dist/boards/review.d.ts +5 -2
  56. package/dist/boards/review.d.ts.map +1 -1
  57. package/dist/boards/review.js +12 -11
  58. package/dist/boards/review.js.map +1 -1
  59. package/dist/boards/semantics.d.ts +160 -20
  60. package/dist/boards/semantics.d.ts.map +1 -1
  61. package/dist/boards/semantics.js +255 -23
  62. package/dist/boards/semantics.js.map +1 -1
  63. package/dist/boards/stored-board.d.ts +73 -1
  64. package/dist/boards/stored-board.d.ts.map +1 -1
  65. package/dist/boards/stored-board.js +157 -11
  66. package/dist/boards/stored-board.js.map +1 -1
  67. package/dist/boards/work-migrations.d.ts +43 -0
  68. package/dist/boards/work-migrations.d.ts.map +1 -0
  69. package/dist/boards/work-migrations.js +353 -0
  70. package/dist/boards/work-migrations.js.map +1 -0
  71. package/dist/boards/work-routes.d.ts +58 -0
  72. package/dist/boards/work-routes.d.ts.map +1 -0
  73. package/dist/boards/work-routes.js +270 -0
  74. package/dist/boards/work-routes.js.map +1 -0
  75. package/dist/boards/work-seeds.d.ts +9 -0
  76. package/dist/boards/work-seeds.d.ts.map +1 -0
  77. package/dist/boards/work-seeds.js +56 -0
  78. package/dist/boards/work-seeds.js.map +1 -0
  79. package/dist/boards/work.d.ts +8 -19
  80. package/dist/boards/work.d.ts.map +1 -1
  81. package/dist/boards/work.js +33 -281
  82. package/dist/boards/work.js.map +1 -1
  83. package/dist/environment/build-runner.d.ts.map +1 -1
  84. package/dist/environment/build-runner.js +2 -2
  85. package/dist/environment/build-runner.js.map +1 -1
  86. package/dist/environment/build-workflow.d.ts.map +1 -1
  87. package/dist/environment/build-workflow.js +6 -5
  88. package/dist/environment/build-workflow.js.map +1 -1
  89. package/dist/environment/build.d.ts +15 -2
  90. package/dist/environment/build.d.ts.map +1 -1
  91. package/dist/environment/build.js +32 -9
  92. package/dist/environment/build.js.map +1 -1
  93. package/dist/factory.d.ts +90 -9
  94. package/dist/factory.d.ts.map +1 -1
  95. package/dist/factory.js +334 -141
  96. package/dist/factory.js.map +1 -1
  97. package/dist/feed-events.d.ts +4 -4
  98. package/dist/feed-events.d.ts.map +1 -1
  99. package/dist/feed-events.js +6 -6
  100. package/dist/feed-events.js.map +1 -1
  101. package/dist/index.d.ts +10 -3
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +7 -4
  104. package/dist/integrations/base.d.ts +12 -13
  105. package/dist/integrations/base.d.ts.map +1 -1
  106. package/dist/integrations/closing-references.d.ts +15 -0
  107. package/dist/integrations/closing-references.d.ts.map +1 -0
  108. package/dist/integrations/closing-references.js +69 -0
  109. package/dist/integrations/closing-references.js.map +1 -0
  110. package/dist/integrations/github/acceptance-labels.d.ts +4 -0
  111. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
  112. package/dist/integrations/github/acceptance-labels.js +1 -1
  113. package/dist/integrations/github/acceptance-labels.js.map +1 -1
  114. package/dist/integrations/github/default-rules.d.ts +17 -75
  115. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  116. package/dist/integrations/github/default-rules.js +134 -77
  117. package/dist/integrations/github/default-rules.js.map +1 -1
  118. package/dist/integrations/github/integration.d.ts.map +1 -1
  119. package/dist/integrations/github/integration.js +7 -3
  120. package/dist/integrations/github/integration.js.map +1 -1
  121. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  122. package/dist/integrations/github/issue-reconciler.js +21 -3
  123. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  124. package/dist/integrations/github/provenance.js +1 -1
  125. package/dist/integrations/github/provenance.js.map +1 -1
  126. package/dist/integrations/github/pull-request-source.d.ts +8 -0
  127. package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
  128. package/dist/integrations/github/pull-request-source.js +17 -0
  129. package/dist/integrations/github/pull-request-source.js.map +1 -0
  130. package/dist/integrations/github/reconcile-worker.d.ts +5 -1
  131. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  132. package/dist/integrations/github/reconcile-worker.js +39 -6
  133. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  134. package/dist/integrations/github/review-status-comment.d.ts +61 -0
  135. package/dist/integrations/github/review-status-comment.d.ts.map +1 -0
  136. package/dist/integrations/github/review-status-comment.js +217 -0
  137. package/dist/integrations/github/review-status-comment.js.map +1 -0
  138. package/dist/integrations/github/review-status-reporter.d.ts +42 -0
  139. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -0
  140. package/dist/integrations/github/review-status-reporter.js +104 -0
  141. package/dist/integrations/github/review-status-reporter.js.map +1 -0
  142. package/dist/integrations/github/review-status.d.ts +28 -0
  143. package/dist/integrations/github/review-status.d.ts.map +1 -0
  144. package/dist/integrations/github/review-status.js +95 -0
  145. package/dist/integrations/github/review-status.js.map +1 -0
  146. package/dist/integrations/github/routes.d.ts +4 -3
  147. package/dist/integrations/github/routes.d.ts.map +1 -1
  148. package/dist/integrations/github/routes.js +11 -91
  149. package/dist/integrations/github/routes.js.map +1 -1
  150. package/dist/integrations/github/rules.d.ts +92 -8
  151. package/dist/integrations/github/rules.d.ts.map +1 -1
  152. package/dist/integrations/github/rules.js +498 -103
  153. package/dist/integrations/github/rules.js.map +1 -1
  154. package/dist/integrations/github/sandbox.d.ts +10 -2
  155. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  156. package/dist/integrations/github/sandbox.js +20 -4
  157. package/dist/integrations/github/sandbox.js.map +1 -1
  158. package/dist/integrations/github/session-subscriptions.js +2 -2
  159. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  160. package/dist/integrations/github/token-refresh.d.ts +2 -1
  161. package/dist/integrations/github/token-refresh.d.ts.map +1 -1
  162. package/dist/integrations/github/token-refresh.js.map +1 -1
  163. package/dist/integrations/gitlab/agent-tools.js +1 -1
  164. package/dist/integrations/gitlab/default-rules.d.ts +96 -39
  165. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  166. package/dist/integrations/gitlab/default-rules.js +109 -46
  167. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  168. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
  169. package/dist/integrations/gitlab/issue-reconciler.js +2 -1
  170. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
  171. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
  172. package/dist/integrations/gitlab/merge-request-reconciler.js +12 -5
  173. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  174. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  175. package/dist/integrations/gitlab/routes.js +2 -6
  176. package/dist/integrations/gitlab/routes.js.map +1 -1
  177. package/dist/integrations/gitlab/rules.d.ts +22 -1
  178. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  179. package/dist/integrations/gitlab/rules.js +188 -34
  180. package/dist/integrations/gitlab/rules.js.map +1 -1
  181. package/dist/integrations/gitlab/session-subscriptions.js +1 -1
  182. package/dist/integrations/incidentio/agent-tools.js +6 -6
  183. package/dist/integrations/incidentio/agent-tools.js.map +1 -1
  184. package/dist/integrations/incidentio/default-rules.d.ts +1 -9
  185. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
  186. package/dist/integrations/incidentio/default-rules.js +6 -7
  187. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  188. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  189. package/dist/integrations/incidentio/issue-reconciler.js +2 -1
  190. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  191. package/dist/integrations/incidentio/routes.d.ts +2 -2
  192. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  193. package/dist/integrations/incidentio/routes.js +11 -17
  194. package/dist/integrations/incidentio/routes.js.map +1 -1
  195. package/dist/integrations/incidentio/rules.d.ts +11 -4
  196. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  197. package/dist/integrations/incidentio/rules.js +52 -16
  198. package/dist/integrations/incidentio/rules.js.map +1 -1
  199. package/dist/integrations/issue-reconciler.js +1 -1
  200. package/dist/integrations/issue-reconciler.js.map +1 -1
  201. package/dist/integrations/jira/agent-tools.js +1 -1
  202. package/dist/integrations/jira/binding-scope.d.ts +5 -6
  203. package/dist/integrations/jira/binding-scope.d.ts.map +1 -1
  204. package/dist/integrations/jira/binding-scope.js +9 -11
  205. package/dist/integrations/jira/binding-scope.js.map +1 -1
  206. package/dist/integrations/jira/default-rules.d.ts +1 -9
  207. package/dist/integrations/jira/default-rules.d.ts.map +1 -1
  208. package/dist/integrations/jira/default-rules.js +6 -7
  209. package/dist/integrations/jira/default-rules.js.map +1 -1
  210. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  211. package/dist/integrations/jira/issue-reconciler.js +2 -1
  212. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  213. package/dist/integrations/jira/routes.d.ts.map +1 -1
  214. package/dist/integrations/jira/routes.js +4 -9
  215. package/dist/integrations/jira/routes.js.map +1 -1
  216. package/dist/integrations/jira/rules.d.ts +11 -4
  217. package/dist/integrations/jira/rules.d.ts.map +1 -1
  218. package/dist/integrations/jira/rules.js +52 -16
  219. package/dist/integrations/jira/rules.js.map +1 -1
  220. package/dist/integrations/linear/agent-tools.d.ts +9 -1
  221. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  222. package/dist/integrations/linear/agent-tools.js +81 -3
  223. package/dist/integrations/linear/agent-tools.js.map +1 -1
  224. package/dist/integrations/linear/default-rules.d.ts +1 -9
  225. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  226. package/dist/integrations/linear/default-rules.js +6 -7
  227. package/dist/integrations/linear/default-rules.js.map +1 -1
  228. package/dist/integrations/linear/integration.d.ts +4 -1
  229. package/dist/integrations/linear/integration.d.ts.map +1 -1
  230. package/dist/integrations/linear/integration.js +21 -1
  231. package/dist/integrations/linear/integration.js.map +1 -1
  232. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
  233. package/dist/integrations/linear/issue-reconciler.js +2 -1
  234. package/dist/integrations/linear/issue-reconciler.js.map +1 -1
  235. package/dist/integrations/linear/routes.d.ts +2 -1
  236. package/dist/integrations/linear/routes.d.ts.map +1 -1
  237. package/dist/integrations/linear/routes.js +16 -21
  238. package/dist/integrations/linear/routes.js.map +1 -1
  239. package/dist/integrations/linear/rules.d.ts +11 -4
  240. package/dist/integrations/linear/rules.d.ts.map +1 -1
  241. package/dist/integrations/linear/rules.js +50 -17
  242. package/dist/integrations/linear/rules.js.map +1 -1
  243. package/dist/integrations/platform/connect/routes.d.ts +7 -1
  244. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  245. package/dist/integrations/platform/connect/routes.js +42 -5
  246. package/dist/integrations/platform/connect/routes.js.map +1 -1
  247. package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
  248. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -0
  249. package/dist/integrations/platform/connect/session-tools.js +35 -0
  250. package/dist/integrations/platform/connect/session-tools.js.map +1 -0
  251. package/dist/integrations/platform/github/event-worker.d.ts +4 -1
  252. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  253. package/dist/integrations/platform/github/event-worker.js +39 -3
  254. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  255. package/dist/integrations/platform/github/integration.d.ts +8 -0
  256. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  257. package/dist/integrations/platform/github/integration.js +132 -90
  258. package/dist/integrations/platform/github/integration.js.map +1 -1
  259. package/dist/integrations/platform/jira/agent-tools.js +1 -1
  260. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  261. package/dist/integrations/platform/jira/routes.js +4 -9
  262. package/dist/integrations/platform/jira/routes.js.map +1 -1
  263. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  264. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  265. package/dist/integrations/platform/linear/event-worker.js +10 -1
  266. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  267. package/dist/integrations/platform/linear/integration.d.ts +1 -1
  268. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  269. package/dist/integrations/platform/linear/integration.js +7 -8
  270. package/dist/integrations/platform/linear/integration.js.map +1 -1
  271. package/dist/integrations/slack/channel-reply-processor.d.ts +2 -0
  272. package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
  273. package/dist/integrations/slack/channel-reply-processor.js +6 -1
  274. package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
  275. package/dist/integrations/slack/chat-tools.js +1 -1
  276. package/dist/integrations/slack/connect-route.d.ts.map +1 -1
  277. package/dist/integrations/slack/connect-route.js +1 -1
  278. package/dist/integrations/slack/connect-route.js.map +1 -1
  279. package/dist/integrations/slack/integration.d.ts +0 -2
  280. package/dist/integrations/slack/integration.d.ts.map +1 -1
  281. package/dist/integrations/slack/integration.js +2 -5
  282. package/dist/integrations/slack/integration.js.map +1 -1
  283. package/dist/integrations/slack/reply-tool.js +1 -1
  284. package/dist/integrations/slack/run-error-card.js +1 -0
  285. package/dist/integrations/slack/run-error-card.js.map +1 -1
  286. package/dist/integrations/slack/share-file-tool.js +1 -1
  287. package/dist/integrations/slack/slack.d.ts +23 -30
  288. package/dist/integrations/slack/slack.d.ts.map +1 -1
  289. package/dist/integrations/slack/slack.js +131 -125
  290. package/dist/integrations/slack/slack.js.map +1 -1
  291. package/dist/integrations/slack/voice-clips.d.ts +32 -0
  292. package/dist/integrations/slack/voice-clips.d.ts.map +1 -0
  293. package/dist/integrations/slack/voice-clips.js +201 -0
  294. package/dist/integrations/slack/voice-clips.js.map +1 -0
  295. package/dist/integrations/workos/integration.d.ts.map +1 -1
  296. package/dist/integrations/workos/integration.js +1 -3
  297. package/dist/integrations/workos/integration.js.map +1 -1
  298. package/dist/links.d.ts +1 -2
  299. package/dist/links.d.ts.map +1 -1
  300. package/dist/links.js +4 -4
  301. package/dist/links.js.map +1 -1
  302. package/dist/mcp/routes.js +2 -2
  303. package/dist/mcp/routes.js.map +1 -1
  304. package/dist/packages/_internals/workspace/dist/index.js +1 -1
  305. package/dist/provider-display-name.d.ts.map +1 -1
  306. package/dist/provider-display-name.js +1 -0
  307. package/dist/provider-display-name.js.map +1 -1
  308. package/dist/routes/attention-parked.d.ts +1 -0
  309. package/dist/routes/attention-parked.d.ts.map +1 -1
  310. package/dist/routes/attention-parked.js +2 -2
  311. package/dist/routes/attention-parked.js.map +1 -1
  312. package/dist/routes/attention-providers.d.ts +0 -25
  313. package/dist/routes/attention-providers.d.ts.map +1 -1
  314. package/dist/routes/attention-providers.js +3 -151
  315. package/dist/routes/attention-providers.js.map +1 -1
  316. package/dist/routes/attention.d.ts +0 -2
  317. package/dist/routes/attention.d.ts.map +1 -1
  318. package/dist/routes/attention.js +2 -13
  319. package/dist/routes/attention.js.map +1 -1
  320. package/dist/routes/automation-runs.d.ts +5 -1
  321. package/dist/routes/automation-runs.d.ts.map +1 -1
  322. package/dist/routes/automation-runs.js +16 -4
  323. package/dist/routes/automation-runs.js.map +1 -1
  324. package/dist/routes/board-snapshot.d.ts +15 -0
  325. package/dist/routes/board-snapshot.d.ts.map +1 -0
  326. package/dist/routes/board-snapshot.js +41 -0
  327. package/dist/routes/board-snapshot.js.map +1 -0
  328. package/dist/routes/boards.d.ts +9 -7
  329. package/dist/routes/boards.d.ts.map +1 -1
  330. package/dist/routes/boards.js +59 -145
  331. package/dist/routes/boards.js.map +1 -1
  332. package/dist/routes/config.d.ts +11 -1
  333. package/dist/routes/config.d.ts.map +1 -1
  334. package/dist/routes/config.js +122 -29
  335. package/dist/routes/config.js.map +1 -1
  336. package/dist/routes/contracts.d.ts +366 -34
  337. package/dist/routes/contracts.d.ts.map +1 -1
  338. package/dist/routes/contracts.js +179 -51
  339. package/dist/routes/contracts.js.map +1 -1
  340. package/dist/routes/feed-events.d.ts +15 -0
  341. package/dist/routes/feed-events.d.ts.map +1 -0
  342. package/dist/routes/feed-events.js +68 -0
  343. package/dist/routes/feed-events.js.map +1 -0
  344. package/dist/routes/fs.d.ts +4 -0
  345. package/dist/routes/fs.d.ts.map +1 -1
  346. package/dist/routes/fs.js +9 -8
  347. package/dist/routes/fs.js.map +1 -1
  348. package/dist/routes/intake-routes.d.ts.map +1 -1
  349. package/dist/routes/intake-routes.js +25 -13
  350. package/dist/routes/intake-routes.js.map +1 -1
  351. package/dist/routes/intake.d.ts +0 -23
  352. package/dist/routes/intake.d.ts.map +1 -1
  353. package/dist/routes/intake.js +16 -314
  354. package/dist/routes/intake.js.map +1 -1
  355. package/dist/routes/knowledge.d.ts.map +1 -1
  356. package/dist/routes/knowledge.js +2 -5
  357. package/dist/routes/knowledge.js.map +1 -1
  358. package/dist/routes/mastra-gateway.d.ts +19 -0
  359. package/dist/routes/mastra-gateway.d.ts.map +1 -0
  360. package/dist/routes/mastra-gateway.js +120 -0
  361. package/dist/routes/mastra-gateway.js.map +1 -0
  362. package/dist/routes/oauth.d.ts.map +1 -1
  363. package/dist/routes/oauth.js +1 -4
  364. package/dist/routes/oauth.js.map +1 -1
  365. package/dist/routes/projects.d.ts +3 -0
  366. package/dist/routes/projects.d.ts.map +1 -1
  367. package/dist/routes/projects.js +80 -61
  368. package/dist/routes/projects.js.map +1 -1
  369. package/dist/routes/provider-credentials.d.ts +6 -1
  370. package/dist/routes/provider-credentials.d.ts.map +1 -1
  371. package/dist/routes/provider-credentials.js +44 -3
  372. package/dist/routes/provider-credentials.js.map +1 -1
  373. package/dist/routes/route.d.ts +8 -0
  374. package/dist/routes/route.d.ts.map +1 -1
  375. package/dist/routes/route.js +5 -1
  376. package/dist/routes/route.js.map +1 -1
  377. package/dist/routes/running-packages.d.ts +13 -0
  378. package/dist/routes/running-packages.d.ts.map +1 -0
  379. package/dist/routes/running-packages.js +45 -0
  380. package/dist/routes/running-packages.js.map +1 -0
  381. package/dist/routes/sandbox-envs.d.ts +26 -0
  382. package/dist/routes/sandbox-envs.d.ts.map +1 -0
  383. package/dist/routes/sandbox-envs.js +180 -0
  384. package/dist/routes/sandbox-envs.js.map +1 -0
  385. package/dist/routes/session-access.d.ts.map +1 -1
  386. package/dist/routes/session-access.js +12 -3
  387. package/dist/routes/session-access.js.map +1 -1
  388. package/dist/routes/skills.d.ts.map +1 -1
  389. package/dist/routes/skills.js +1 -4
  390. package/dist/routes/skills.js.map +1 -1
  391. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  392. package/dist/routes/source-control-sessions.js +1 -3
  393. package/dist/routes/source-control-sessions.js.map +1 -1
  394. package/dist/routes/source-control-settings.d.ts.map +1 -1
  395. package/dist/routes/source-control-settings.js +3 -2
  396. package/dist/routes/source-control-settings.js.map +1 -1
  397. package/dist/routes/surface.d.ts +13 -9
  398. package/dist/routes/surface.d.ts.map +1 -1
  399. package/dist/routes/surface.js +116 -43
  400. package/dist/routes/surface.js.map +1 -1
  401. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  402. package/dist/routes/tenant-credentials.js +5 -1
  403. package/dist/routes/tenant-credentials.js.map +1 -1
  404. package/dist/routes/voice.d.ts +48 -0
  405. package/dist/routes/voice.d.ts.map +1 -0
  406. package/dist/routes/voice.js +248 -0
  407. package/dist/routes/voice.js.map +1 -0
  408. package/dist/routes/work-items.d.ts +0 -3
  409. package/dist/routes/work-items.d.ts.map +1 -1
  410. package/dist/routes/work-items.js +39 -14
  411. package/dist/routes/work-items.js.map +1 -1
  412. package/dist/rules/binding-context.d.ts.map +1 -1
  413. package/dist/rules/binding-context.js +1 -0
  414. package/dist/rules/binding-context.js.map +1 -1
  415. package/dist/rules/decision-applicability.js +1 -1
  416. package/dist/rules/dispatcher.d.ts +28 -9
  417. package/dist/rules/dispatcher.d.ts.map +1 -1
  418. package/dist/rules/dispatcher.js +734 -143
  419. package/dist/rules/dispatcher.js.map +1 -1
  420. package/dist/rules/event-rules.d.ts +71 -1
  421. package/dist/rules/event-rules.d.ts.map +1 -1
  422. package/dist/rules/event-rules.js +94 -1
  423. package/dist/rules/event-rules.js.map +1 -1
  424. package/dist/rules/index.d.ts +2 -4
  425. package/dist/rules/index.d.ts.map +1 -1
  426. package/dist/rules/index.js +2 -3
  427. package/dist/rules/phase-goal.d.ts +54 -0
  428. package/dist/rules/phase-goal.d.ts.map +1 -0
  429. package/dist/rules/phase-goal.js +70 -0
  430. package/dist/rules/phase-goal.js.map +1 -0
  431. package/dist/rules/phase-tools.d.ts +11 -0
  432. package/dist/rules/phase-tools.d.ts.map +1 -0
  433. package/dist/rules/phase-tools.js +19 -0
  434. package/dist/rules/phase-tools.js.map +1 -0
  435. package/dist/rules/processor.d.ts.map +1 -1
  436. package/dist/rules/processor.js +116 -15
  437. package/dist/rules/processor.js.map +1 -1
  438. package/dist/rules/review-source-tool.d.ts +4 -1
  439. package/dist/rules/review-source-tool.d.ts.map +1 -1
  440. package/dist/rules/review-source-tool.js +24 -4
  441. package/dist/rules/review-source-tool.js.map +1 -1
  442. package/dist/rules/rule-group.d.ts +1 -1
  443. package/dist/rules/rule-group.d.ts.map +1 -1
  444. package/dist/rules/rule-group.js +15 -6
  445. package/dist/rules/rule-group.js.map +1 -1
  446. package/dist/rules/start-coordinator.d.ts +5 -1
  447. package/dist/rules/start-coordinator.d.ts.map +1 -1
  448. package/dist/rules/start-coordinator.js +9 -3
  449. package/dist/rules/start-coordinator.js.map +1 -1
  450. package/dist/rules/tools.d.ts.map +1 -1
  451. package/dist/rules/tools.js +39 -28
  452. package/dist/rules/tools.js.map +1 -1
  453. package/dist/rules/transition-service.d.ts +10 -7
  454. package/dist/rules/transition-service.d.ts.map +1 -1
  455. package/dist/rules/transition-service.js +63 -55
  456. package/dist/rules/transition-service.js.map +1 -1
  457. package/dist/rules/types.d.ts +140 -39
  458. package/dist/rules/types.d.ts.map +1 -1
  459. package/dist/rules/types.js +7 -41
  460. package/dist/rules/types.js.map +1 -1
  461. package/dist/rules/validation.d.ts.map +1 -1
  462. package/dist/rules/validation.js +89 -4
  463. package/dist/rules/validation.js.map +1 -1
  464. package/dist/run-error.d.ts +1 -1
  465. package/dist/run-error.d.ts.map +1 -1
  466. package/dist/run-error.js +38 -5
  467. package/dist/run-error.js.map +1 -1
  468. package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
  469. package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
  470. package/dist/sandbox/sandbox-env-cache.js +140 -0
  471. package/dist/sandbox/sandbox-env-cache.js.map +1 -0
  472. package/dist/sandbox/sandbox-env.d.ts +77 -0
  473. package/dist/sandbox/sandbox-env.d.ts.map +1 -0
  474. package/dist/sandbox/sandbox-env.js +130 -0
  475. package/dist/sandbox/sandbox-env.js.map +1 -0
  476. package/dist/secret-encryption.d.ts +21 -0
  477. package/dist/secret-encryption.d.ts.map +1 -1
  478. package/dist/secret-encryption.js +31 -4
  479. package/dist/secret-encryption.js.map +1 -1
  480. package/dist/session/credential-policy.d.ts +2 -2
  481. package/dist/session/credential-policy.d.ts.map +1 -1
  482. package/dist/session/credential-policy.js +3 -3
  483. package/dist/session/credential-policy.js.map +1 -1
  484. package/dist/session/default-model-hydration.d.ts +2 -2
  485. package/dist/session/default-model-hydration.d.ts.map +1 -1
  486. package/dist/session/default-model-hydration.js +4 -4
  487. package/dist/session/default-model-hydration.js.map +1 -1
  488. package/dist/session/live-sessions.d.ts +11 -4
  489. package/dist/session/live-sessions.d.ts.map +1 -1
  490. package/dist/session/live-sessions.js +31 -10
  491. package/dist/session/live-sessions.js.map +1 -1
  492. package/dist/session/self-review-gate.d.ts +6 -4
  493. package/dist/session/self-review-gate.d.ts.map +1 -1
  494. package/dist/session/self-review-gate.js +9 -12
  495. package/dist/session/self-review-gate.js.map +1 -1
  496. package/dist/session/session-threads.d.ts +10 -3
  497. package/dist/session/session-threads.d.ts.map +1 -1
  498. package/dist/session/session-threads.js +11 -1
  499. package/dist/session/session-threads.js.map +1 -1
  500. package/dist/session/source-control-tools.d.ts +39 -13
  501. package/dist/session/source-control-tools.d.ts.map +1 -1
  502. package/dist/session/source-control-tools.js +55 -61
  503. package/dist/session/source-control-tools.js.map +1 -1
  504. package/dist/session/work-item-state-processor.d.ts +24 -0
  505. package/dist/session/work-item-state-processor.d.ts.map +1 -0
  506. package/dist/session/work-item-state-processor.js +275 -0
  507. package/dist/session/work-item-state-processor.js.map +1 -0
  508. package/dist/skills/catalog.js +1 -1
  509. package/dist/storage/domains/audit/actions.d.ts +3 -2
  510. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  511. package/dist/storage/domains/audit/actions.js +7 -5
  512. package/dist/storage/domains/audit/actions.js.map +1 -1
  513. package/dist/storage/domains/audit/domain.d.ts.map +1 -1
  514. package/dist/storage/domains/audit/domain.js +1 -3
  515. package/dist/storage/domains/audit/domain.js.map +1 -1
  516. package/dist/storage/domains/boards/base.d.ts +107 -23
  517. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  518. package/dist/storage/domains/boards/base.js +201 -65
  519. package/dist/storage/domains/boards/base.js.map +1 -1
  520. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  521. package/dist/storage/domains/boards/schemas.js +25 -1
  522. package/dist/storage/domains/boards/schemas.js.map +1 -1
  523. package/dist/storage/domains/channel-identity/base.d.ts +0 -4
  524. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
  525. package/dist/storage/domains/channel-identity/base.js +0 -7
  526. package/dist/storage/domains/channel-identity/base.js.map +1 -1
  527. package/dist/storage/domains/intake/base.d.ts +5 -45
  528. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  529. package/dist/storage/domains/intake/base.js +11 -89
  530. package/dist/storage/domains/intake/base.js.map +1 -1
  531. package/dist/storage/domains/memory-settings/base.d.ts +0 -8
  532. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -1
  533. package/dist/storage/domains/memory-settings/base.js +1 -11
  534. package/dist/storage/domains/memory-settings/base.js.map +1 -1
  535. package/dist/storage/domains/projects/base.d.ts +23 -9
  536. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  537. package/dist/storage/domains/projects/base.js +24 -8
  538. package/dist/storage/domains/projects/base.js.map +1 -1
  539. package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
  540. package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
  541. package/dist/storage/domains/sandbox-envs/base.js +227 -0
  542. package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
  543. package/dist/storage/domains/voice-settings/base.d.ts +31 -0
  544. package/dist/storage/domains/voice-settings/base.d.ts.map +1 -0
  545. package/dist/storage/domains/voice-settings/base.js +81 -0
  546. package/dist/storage/domains/voice-settings/base.js.map +1 -0
  547. package/dist/storage/domains/work-items/base.d.ts +93 -24
  548. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  549. package/dist/storage/domains/work-items/base.js +413 -188
  550. package/dist/storage/domains/work-items/base.js.map +1 -1
  551. package/dist/storage/domains/work-items/board-version.d.ts +6 -2
  552. package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
  553. package/dist/storage/domains/work-items/board-version.js +20 -9
  554. package/dist/storage/domains/work-items/board-version.js.map +1 -1
  555. package/dist/storage/domains/work-items/cards.d.ts +33 -5
  556. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  557. package/dist/storage/domains/work-items/cards.js +208 -25
  558. package/dist/storage/domains/work-items/cards.js.map +1 -1
  559. package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
  560. package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
  561. package/dist/storage/domains/work-items/legacy-review.js +109 -0
  562. package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
  563. package/dist/storage/domains/work-items/metrics.d.ts +12 -4
  564. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  565. package/dist/storage/domains/work-items/metrics.js +14 -32
  566. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  567. package/dist/storage/domains/work-items/work-item-schema.d.ts +6 -2
  568. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  569. package/dist/storage/domains/work-items/work-item-schema.js +83 -27
  570. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  571. package/dist/timing.d.ts +1 -0
  572. package/dist/timing.d.ts.map +1 -1
  573. package/dist/timing.js +1 -1
  574. package/dist/timing.js.map +1 -1
  575. package/dist/tools/approval-tools.d.ts.map +1 -1
  576. package/dist/tools/approval-tools.js +28 -9
  577. package/dist/tools/approval-tools.js.map +1 -1
  578. package/dist/tools/index.d.ts +1 -1
  579. package/dist/tools/index.js +1 -1
  580. package/dist/tools/index.js.map +1 -1
  581. package/dist/tools/messaging-tools.d.ts +3 -0
  582. package/dist/tools/messaging-tools.d.ts.map +1 -1
  583. package/dist/tools/messaging-tools.js +2 -1
  584. package/dist/tools/messaging-tools.js.map +1 -1
  585. package/dist/tools/read-tools.d.ts +10 -6
  586. package/dist/tools/read-tools.d.ts.map +1 -1
  587. package/dist/tools/read-tools.js +89 -39
  588. package/dist/tools/read-tools.js.map +1 -1
  589. package/dist/tools/reports.d.ts +1 -0
  590. package/dist/tools/reports.d.ts.map +1 -1
  591. package/dist/tools/reports.js +2 -1
  592. package/dist/tools/reports.js.map +1 -1
  593. package/dist/tools/run-watch.d.ts +1 -1
  594. package/dist/tools/run-watch.d.ts.map +1 -1
  595. package/dist/tools/run-watch.js +1 -0
  596. package/dist/tools/run-watch.js.map +1 -1
  597. package/dist/tools/sandbox-tools.js +1 -1
  598. package/dist/tools/session-tools.d.ts +1 -1
  599. package/dist/tools/session-tools.d.ts.map +1 -1
  600. package/dist/tools/session-tools.js +1 -1
  601. package/dist/tools/session-tools.js.map +1 -1
  602. package/dist/tools/sessions-state-processor.d.ts +3 -1
  603. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  604. package/dist/tools/sessions-state-processor.js +13 -4
  605. package/dist/tools/sessions-state-processor.js.map +1 -1
  606. package/dist/tools/side-sessions.d.ts +2 -0
  607. package/dist/tools/side-sessions.d.ts.map +1 -1
  608. package/dist/tools/side-sessions.js +2 -1
  609. package/dist/tools/side-sessions.js.map +1 -1
  610. package/dist/tools/work-item-tools.d.ts +0 -3
  611. package/dist/tools/work-item-tools.d.ts.map +1 -1
  612. package/dist/tools/work-item-tools.js +10 -20
  613. package/dist/tools/work-item-tools.js.map +1 -1
  614. package/dist/voice/rate-limit.d.ts +13 -0
  615. package/dist/voice/rate-limit.d.ts.map +1 -0
  616. package/dist/voice/rate-limit.js +36 -0
  617. package/dist/voice/rate-limit.js.map +1 -0
  618. package/dist/voice/realtime.d.ts +13 -0
  619. package/dist/voice/realtime.d.ts.map +1 -0
  620. package/dist/voice/realtime.js +56 -0
  621. package/dist/voice/realtime.js.map +1 -0
  622. package/dist/voice/transcription.d.ts +51 -0
  623. package/dist/voice/transcription.d.ts.map +1 -0
  624. package/dist/voice/transcription.js +112 -0
  625. package/dist/voice/transcription.js.map +1 -0
  626. package/dist/work-item-branch.d.ts +13 -0
  627. package/dist/work-item-branch.d.ts.map +1 -1
  628. package/dist/work-item-branch.js +16 -1
  629. package/dist/work-item-branch.js.map +1 -1
  630. package/dist/work-items/create-work-item.d.ts +6 -0
  631. package/dist/work-items/create-work-item.d.ts.map +1 -1
  632. package/dist/work-items/create-work-item.js +28 -3
  633. package/dist/work-items/create-work-item.js.map +1 -1
  634. package/dist/work-items/description-context.d.ts +5 -0
  635. package/dist/work-items/description-context.d.ts.map +1 -0
  636. package/dist/work-items/description-context.js +17 -0
  637. package/dist/work-items/description-context.js.map +1 -0
  638. package/dist/work-items/providers/base.d.ts +4 -1
  639. package/dist/work-items/providers/base.d.ts.map +1 -1
  640. package/dist/work-items/providers/base.js +6 -1
  641. package/dist/work-items/providers/base.js.map +1 -1
  642. package/dist/work-items/providers/github.d.ts.map +1 -1
  643. package/dist/work-items/providers/github.js +2 -1
  644. package/dist/work-items/providers/github.js.map +1 -1
  645. package/dist/work-items/providers/gitlab.d.ts.map +1 -1
  646. package/dist/work-items/providers/gitlab.js +2 -1
  647. package/dist/work-items/providers/gitlab.js.map +1 -1
  648. package/dist/work-items/providers/jira.d.ts.map +1 -1
  649. package/dist/work-items/providers/jira.js +3 -2
  650. package/dist/work-items/providers/jira.js.map +1 -1
  651. package/dist/work-items/providers/linear.d.ts.map +1 -1
  652. package/dist/work-items/providers/linear.js +3 -2
  653. package/dist/work-items/providers/linear.js.map +1 -1
  654. package/dist/work-items/providers/types.d.ts +6 -0
  655. package/dist/work-items/providers/types.d.ts.map +1 -1
  656. package/dist/work-items/split-backfill.d.ts +13 -0
  657. package/dist/work-items/split-backfill.d.ts.map +1 -0
  658. package/dist/work-items/split-backfill.js +32 -0
  659. package/dist/work-items/split-backfill.js.map +1 -0
  660. package/dist/work-items/split-migration.d.ts +39 -2
  661. package/dist/work-items/split-migration.d.ts.map +1 -1
  662. package/dist/work-items/split-migration.js +178 -70
  663. package/dist/work-items/split-migration.js.map +1 -1
  664. package/dist/workspace.d.ts +3 -1
  665. package/dist/workspace.d.ts.map +1 -1
  666. package/dist/workspace.js +118 -34
  667. package/dist/workspace.js.map +1 -1
  668. package/factory-skills/configure-factory-rules/SKILL.md +13 -11
  669. package/factory-skills/factory-build/SKILL.md +64 -0
  670. package/factory-skills/factory-gitlab-rereview/SKILL.md +4 -4
  671. package/factory-skills/factory-gitlab-review/SKILL.md +6 -6
  672. package/factory-skills/factory-plan/SKILL.md +8 -10
  673. package/factory-skills/factory-rereview/SKILL.md +74 -28
  674. package/factory-skills/factory-review/SKILL.md +85 -29
  675. package/factory-skills/factory-self-review/SKILL.md +32 -13
  676. package/factory-skills/factory-triage/SKILL.md +36 -32
  677. package/package.json +12 -11
  678. package/dist/boards/index.js.map +0 -1
  679. package/dist/boards/pull-request-review.d.ts +0 -14
  680. package/dist/boards/pull-request-review.d.ts.map +0 -1
  681. package/dist/boards/pull-request-review.js +0 -81
  682. package/dist/boards/pull-request-review.js.map +0 -1
  683. package/dist/boards/work-tool-rules.d.ts +0 -8
  684. package/dist/boards/work-tool-rules.d.ts.map +0 -1
  685. package/dist/boards/work-tool-rules.js +0 -19
  686. package/dist/boards/work-tool-rules.js.map +0 -1
  687. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
  688. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
  689. package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
  690. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
  691. package/dist/integrations/slack/emoji.d.ts +0 -3
  692. package/dist/integrations/slack/emoji.d.ts.map +0 -1
  693. package/dist/integrations/slack/emoji.js +0 -11
  694. package/dist/integrations/slack/emoji.js.map +0 -1
  695. package/dist/integrations/slack/feed-publisher.d.ts +0 -26
  696. package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
  697. package/dist/integrations/slack/feed-publisher.js +0 -43
  698. package/dist/integrations/slack/feed-publisher.js.map +0 -1
  699. package/dist/routes/attention-activity.d.ts +0 -23
  700. package/dist/routes/attention-activity.d.ts.map +0 -1
  701. package/dist/routes/attention-activity.js +0 -154
  702. package/dist/routes/attention-activity.js.map +0 -1
  703. package/dist/rules/resolve.d.ts +0 -15
  704. package/dist/rules/resolve.d.ts.map +0 -1
  705. package/dist/rules/resolve.js +0 -22
  706. package/dist/rules/resolve.js.map +0 -1
  707. package/dist/storage/domains/comments/activity.d.ts +0 -40
  708. package/dist/storage/domains/comments/activity.d.ts.map +0 -1
  709. package/dist/storage/domains/comments/activity.js +0 -93
  710. package/dist/storage/domains/comments/activity.js.map +0 -1
  711. package/dist/storage/domains/comments/actor.d.ts +0 -51
  712. package/dist/storage/domains/comments/actor.d.ts.map +0 -1
  713. package/dist/storage/domains/comments/actor.js +0 -37
  714. package/dist/storage/domains/comments/actor.js.map +0 -1
  715. package/dist/storage/domains/comments/base.d.ts +0 -245
  716. package/dist/storage/domains/comments/base.d.ts.map +0 -1
  717. package/dist/storage/domains/comments/base.js +0 -539
  718. package/dist/storage/domains/comments/base.js.map +0 -1
  719. package/dist/storage/domains/comments/domain.d.ts +0 -135
  720. package/dist/storage/domains/comments/domain.d.ts.map +0 -1
  721. package/dist/storage/domains/comments/domain.js +0 -284
  722. package/dist/storage/domains/comments/domain.js.map +0 -1
  723. package/dist/storage/domains/comments/feed-context.d.ts +0 -22
  724. package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
  725. package/dist/storage/domains/comments/feed-context.js +0 -88
  726. package/dist/storage/domains/comments/feed-context.js.map +0 -1
  727. package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
  728. package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
  729. package/dist/storage/domains/comments/feed-sync.js +0 -1
  730. package/dist/storage/domains/comments/parse.d.ts +0 -23
  731. package/dist/storage/domains/comments/parse.d.ts.map +0 -1
  732. package/dist/storage/domains/comments/parse.js +0 -89
  733. package/dist/storage/domains/comments/parse.js.map +0 -1
  734. package/dist/storage/domains/comments/routes.d.ts +0 -24
  735. package/dist/storage/domains/comments/routes.d.ts.map +0 -1
  736. package/dist/storage/domains/comments/routes.js +0 -301
  737. package/dist/storage/domains/comments/routes.js.map +0 -1
  738. package/dist/storage/domains/comments/schema.d.ts +0 -5
  739. package/dist/storage/domains/comments/schema.d.ts.map +0 -1
  740. package/dist/storage/domains/comments/schema.js +0 -178
  741. package/dist/storage/domains/comments/schema.js.map +0 -1
  742. package/dist/storage/domains/comments/wire.d.ts +0 -40
  743. package/dist/storage/domains/comments/wire.d.ts.map +0 -1
  744. package/dist/storage/domains/comments/wire.js +0 -36
  745. package/dist/storage/domains/comments/wire.js.map +0 -1
  746. package/factory-skills/factory-complete-issue/SKILL.md +0 -24
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/rules/types.ts"],"sourcesContent":["import type { ExternalWorkItemSource } from '../storage/domains/work-items/base.js';\nimport type { WorkItemRow } from '../storage/domains/work-items/work-item-schema.js';\n\nexport type WorkItemSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'manual';\n\nexport function externalSourceForWorkItem(\n source: WorkItemSource,\n sourceKey: string,\n url?: string,\n): ExternalWorkItemSource {\n const [integrationId, type] =\n source === 'github-pr'\n ? ['github', 'pull-request']\n : source === 'github-issue'\n ? ['github', 'issue']\n : source === 'gitlab-pr'\n ? ['gitlab', 'pull-request']\n : source === 'gitlab-issue'\n ? ['gitlab', 'issue']\n : source === 'linear-issue'\n ? ['linear', 'issue']\n : source === 'jira-issue'\n ? ['jira', 'issue']\n : source === 'incidentio-follow-up'\n ? ['incidentio', 'issue']\n : ['factory', 'manual'];\n return { integrationId, type, externalId: sourceKey, ...(url ? { url } : {}) };\n}\n\n/** The source label that holds an issue at rest until a maintainer decides; compared lowercased. */\nexport const NEEDS_APPROVAL_LABEL = 'status: needs approval';\nexport const AUTO_TRIAGED_LABEL = 'status: auto-triaged';\n\n// The label only holds a card at rest: once a person moves it into a working lane, the\n// label is stale until the source catches up (Factory removes it on that move).\nexport function needsApproval(item: { workItem: Pick<WorkItemRow, 'labels'>; stages?: readonly string[] }): boolean {\n const labels = item.workItem.labels;\n if (!Array.isArray(labels)) return false;\n return (\n labels.some(label => typeof label === 'string' && label.toLowerCase() === NEEDS_APPROVAL_LABEL) &&\n (item.stages ?? ['intake']).every(stage => stage === 'intake' || stage === 'triage')\n );\n}\n\nexport function workItemSource(source: ExternalWorkItemSource | null): WorkItemSource {\n if (!source) return 'manual';\n if (source.integrationId === 'linear') return 'linear-issue';\n if (source.integrationId === 'gitlab') return source.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n if (source.integrationId === 'jira') return 'jira-issue';\n if (source.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io have provider-specific\n // rules; anything else (a Slack thread, say) is a plain work item, not a\n // mislabeled GitHub issue.\n if (source.integrationId !== 'github') return 'manual';\n return source.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\n/** The card's author is inside the write-access circle, or the card is Factory's own PR. */\nexport function authorTrusted(metadata: Record<string, unknown> | null | undefined): boolean {\n return metadata?.authorTrusted === true || metadata?.factoryAuthored === true;\n}\n\n// Authored outside the write-access circle: a missing trust stamp fails closed until\n// the reconcile sweep backfills it, and Factory's own PRs pass through `factoryAuthored`.\nexport function externallyAuthored(item: { source: string; metadata: Record<string, unknown> | null }): boolean {\n if (!['github-pr', 'github-issue', 'gitlab-pr', 'gitlab-issue'].includes(item.source)) return false;\n return !authorTrusted(item.metadata);\n}\n\nexport function externallyAuthoredWorkItem(item: {\n externalSource: ExternalWorkItemSource | null;\n metadata: Record<string, unknown> | null;\n}): boolean {\n return externallyAuthored({ source: workItemSource(item.externalSource), metadata: item.metadata });\n}\n\nexport const FACTORY_RULE_STAGES = [\n 'intake',\n 'triage',\n 'planning',\n 'execute',\n 'review',\n 'pr-review',\n 'done',\n 'canceled',\n] as const;\nexport type FactoryRuleStage = (typeof FACTORY_RULE_STAGES)[number] | (string & {});\n\n// Each role and the working stage its run holds the card in. Key order is the\n// seat pipeline order — Resume depth derives from it.\nexport const FACTORY_ROLE_STAGES = {\n triage: 'triage',\n plan: 'planning',\n work: 'execute',\n review: 'review',\n} as const satisfies Record<string, FactoryRuleStage>;\nexport type FactoryRole = keyof typeof FACTORY_ROLE_STAGES;\n\nexport function isFactoryRole(value: string): value is FactoryRole {\n return value in FACTORY_ROLE_STAGES;\n}\n\nexport const FACTORY_TRIAGE_TYPES = [\n 'bug',\n 'feature request',\n 'docs',\n 'question/support',\n 'maintenance',\n 'duplicate',\n 'resolved',\n 'invalid',\n 'spam',\n 'out-of-scope',\n 'other',\n] as const;\nexport type FactoryTriageType = (typeof FACTORY_TRIAGE_TYPES)[number];\n\nexport function isFactoryTriageType(value: unknown): value is FactoryTriageType {\n return typeof value === 'string' && FACTORY_TRIAGE_TYPES.some(type => type === value);\n}\n\nexport function isFactoryRuleStage(value: unknown): value is FactoryRuleStage {\n return typeof value === 'string' && FACTORY_RULE_STAGES.some(stage => stage === value);\n}\n\nexport function factoryRuleStage(stages: readonly string[]): FactoryRuleStage | undefined {\n const stage = stages.length === 1 ? stages[0] : undefined;\n return typeof stage === 'string' && stage.length > 0 ? stage : undefined;\n}\n\nexport function isTerminalFactoryRuleStage(stages: readonly string[]): boolean {\n const stage = factoryRuleStage(stages);\n return stage === 'done' || stage === 'canceled';\n}\n\n/** Working lanes hold cards with a seat engaged; Intake, Done and Canceled rest them. */\nexport function isWorkingFactoryRuleStage(stage: FactoryRuleStage): boolean {\n return stage !== 'intake' && !isTerminalFactoryRuleStage([stage]);\n}\n\n// Consulted only for the Intake exit: roles don't own lanes, so a card already\n// in a working or terminal lane stays put when a run starts.\nexport function factoryLaneForRole(role: string): FactoryRuleStage | undefined {\n return isFactoryRole(role) ? FACTORY_ROLE_STAGES[role] : undefined;\n}\n\nexport const FACTORY_RULE_BOARDS = ['work', 'review'] as const;\nexport type FactoryRuleBoard = (typeof FACTORY_RULE_BOARDS)[number] | (string & {});\n\nexport const FACTORY_RULE_SOURCES = [\n 'issue',\n 'pullRequest',\n 'gitlabIssue',\n 'gitlabPullRequest',\n 'linearIssue',\n 'jiraIssue',\n 'incidentioFollowUp',\n 'manual',\n] as const;\nexport type FactoryRuleSource = (typeof FACTORY_RULE_SOURCES)[number];\n\nexport const FACTORY_GITHUB_EVENTS = [\n 'issueOpened',\n 'issueEdited',\n 'issueClosed',\n 'issueCommentCreated',\n 'issueCommentEdited',\n 'issueCommentDeleted',\n 'pullRequestOpened',\n 'pullRequestUpdated',\n 'pullRequestCommentCreated',\n 'pullRequestReviewRequested',\n 'pullRequestReviewSubmitted',\n 'pullRequestMerged',\n 'pullRequestClosed',\n] as const;\nexport type FactoryGithubEventName = (typeof FACTORY_GITHUB_EVENTS)[number];\n\nexport const FACTORY_GITLAB_EVENTS = [\n 'issueOpened',\n 'issueUpdated',\n 'issueClosed',\n 'issueCommented',\n 'mergeRequestOpened',\n 'mergeRequestUpdated',\n 'mergeRequestCommented',\n 'mergeRequestMerged',\n 'mergeRequestClosed',\n] as const;\nexport type FactoryGitLabEventName = (typeof FACTORY_GITLAB_EVENTS)[number];\n\nexport const FACTORY_LINEAR_EVENTS = ['issueObserved', 'issueClosed'] as const;\nexport type FactoryLinearEventName = (typeof FACTORY_LINEAR_EVENTS)[number];\n\nexport const FACTORY_JIRA_EVENTS = ['issueObserved', 'issueClosed'] as const;\nexport type FactoryJiraEventName = (typeof FACTORY_JIRA_EVENTS)[number];\n\nexport const FACTORY_INCIDENTIO_EVENTS = ['followUpObserved', 'followUpClosed'] as const;\nexport type FactoryIncidentioEventName = (typeof FACTORY_INCIDENTIO_EVENTS)[number];\n\nexport type FactoryRuleJsonValue =\n | null\n | boolean\n | number\n | string\n | FactoryRuleJsonValue[]\n | { [key: string]: FactoryRuleJsonValue };\n\nexport interface FactoryRuleItemContext {\n workItem: WorkItemRow;\n id: string;\n source: WorkItemSource;\n sourceKey: string | null;\n parentWorkItemId: string | null;\n title: string;\n url: string | null;\n stages: readonly string[];\n /**\n * @deprecated Factory no longer records triage acceptance; this is the value stamped on older\n * cards, and `null` for every card since. A person moving the card on is the approval.\n */\n acceptedAt: Date | null;\n /** Factory-owned process state and trust stamps. */\n metadata: Record<string, unknown> | null;\n}\n\nexport type FactoryRuleActor =\n | { type: 'human'; id: string }\n | { type: 'agent'; bindingId: string; role: string }\n | { type: 'github'; login: string; trusted: boolean; factoryAuthored: boolean }\n | { type: 'gitlab'; username: string; trusted: boolean; factoryAuthored: boolean }\n | { type: 'system'; id: string };\n\nexport interface FactoryRuleIngressIdentity {\n type: 'human' | 'agent' | 'toolResult' | 'github' | 'gitlab' | 'linear' | 'jira' | 'incidentio' | 'rule';\n id: string;\n}\n\nexport interface FactoryRuleCausalEntry {\n ingressId: string;\n decisionType: FactoryCommitDecision['type'];\n}\n\n/** The phase a card sits in, as its board declares it. */\nexport interface FactoryRulePhaseContext {\n id: string;\n kind: 'resting' | 'working' | 'terminal';\n /** Session context a working phase runs in; absent for resting and terminal phases. */\n context?: string;\n /** @deprecated Use `context`. */\n role?: string;\n /** Phases the card may move to from here. */\n nextPhases: readonly string[];\n /** Outcome names the phase declares, e.g. `approved` or `canceled`; empty when it declares none. */\n outcomes: readonly string[];\n}\n\nexport interface FactoryRuleContextBase {\n tenant: { orgId: string; projectId: string };\n actor: FactoryRuleActor;\n ingress: FactoryRuleIngressIdentity;\n cause: string;\n causalChain: readonly FactoryRuleCausalEntry[];\n configVersion: string;\n}\n\nexport interface FactoryBoundRuleContext extends FactoryRuleContextBase {\n item: FactoryRuleItemContext;\n board: FactoryRuleBoard;\n itemRevision: number;\n}\n\nexport interface FactoryStageRuleContext extends FactoryBoundRuleContext {\n source: FactoryRuleSource;\n stage: FactoryRuleStage;\n fromStage: FactoryRuleStage;\n toStage: FactoryRuleStage;\n /** Project switch: Work items get an independent self-review before the change request opens. Unset means off. */\n selfReviewEnabled?: boolean;\n}\n\nexport interface FactoryToolResultRuleContext extends FactoryBoundRuleContext {\n toolName: string;\n threadId: string;\n assistantMessageId: string;\n toolCallId: string;\n result: {\n status: 'success' | 'error';\n value: FactoryRuleJsonValue;\n };\n}\n\nexport interface FactoryGithubRuleContext extends FactoryRuleContextBase {\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /**\n * Board an issue's labels route it to, when the project has a matching label route and that board\n * is installed. Absent for pull requests and for issues whose labels select nothing.\n */\n intake?: FactoryRuleIntakeTarget;\n /**\n * Set on the one evaluation per pull request delivery that files the pull\n * request's own Review card. Opening a pull request concerns two cards — that\n * Review card and the Work item that authored the pull request — so the rule\n * answers for the two separately: the arrival carries this flag and is\n * committed against the authoring item when resolution found one, which is\n * what links the new card to it, while the authoring item's own evaluation\n * leaves the flag unset.\n */\n pullRequestIntake?: boolean;\n event: FactoryGithubEventName;\n deliveryId: string;\n factory: { createdAt: string };\n /** `installationId` is the GitHub App installation the delivery arrived through. */\n repository: { id: number; fullName: string; installationId?: number };\n issue?: {\n number: number;\n title: string;\n url: string;\n createdAt?: string;\n updatedAt?: string;\n assignees?: string[];\n labels?: string[];\n state?: 'open' | 'closed';\n author?: string;\n /** GitHub close reason: `completed`, `not_planned`, or `duplicate`. */\n stateReason?: string;\n };\n issueChange?: { title: boolean; body: boolean };\n issueComment?: {\n id: number;\n body?: string;\n url?: string;\n author?: string;\n authorType?: string;\n createdAt?: string;\n updatedAt?: string;\n };\n pullRequest?: {\n number: number;\n title: string;\n url: string;\n createdAt?: string;\n state: 'open' | 'closed';\n draft: boolean;\n merged: boolean;\n assignees?: string[];\n requestedReviewers?: string[];\n labels?: string[];\n author?: string;\n factoryAuthored: boolean;\n headBranch: string;\n baseBranch: string;\n };\n /** Present on `pullRequestReviewRequested`: who review was (re-)requested from. */\n reviewRequest?: { reviewer: string; factoryReviewer: boolean };\n /** Present when a PR comment uses Factory's exact review command. */\n reviewCommand?: { command: 'review' | 're-review'; target: string };\n /**\n * Present on `pullRequestReviewSubmitted`: the review that was just posted, or a\n * request-changes review whose body was edited to a new Factory verdict.\n */\n review?: { id: number; state: string; url: string; author?: string; body?: string };\n}\n\n/**\n * Where an intake source binding says new items from this source should land.\n * Absent when the source is unbound or bound without a board (built-in routing).\n */\nexport interface FactoryRuleIntakeTarget {\n board: string;\n initialPhase: string;\n}\n\n/**\n * Where a source-closed rule moves the card, from the `sourceClosed` mapping its installed board\n * declares. Absent when the card's board is not installed or declares no mapping.\n */\nexport interface FactoryRuleBoardClosure {\n /** Title of the card's board, for messages. */\n boardTitle: string;\n /** Terminal phase for a source that was completed. */\n completed: FactoryRuleBoardClosurePhase;\n /** Terminal phase for a source that was canceled or not planned. */\n canceled: FactoryRuleBoardClosurePhase;\n /** Whether the card already sits in a terminal phase of its board. */\n itemTerminal: boolean;\n}\n\nexport interface FactoryRuleBoardClosurePhase {\n phase: string;\n title: string;\n}\n\nexport interface FactoryGitLabRuleContext extends FactoryRuleContextBase {\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n intake?: FactoryRuleIntakeTarget;\n event: FactoryGitLabEventName;\n deliveryId: string;\n factory: { createdAt: string };\n repository: { id: number; fullName: string; host: string };\n issue?: {\n number: number;\n sourceKey: string;\n title: string;\n url: string;\n createdAt?: string;\n updatedAt?: string;\n assignees?: string[];\n labels?: string[];\n labelColors?: Record<string, string>;\n state?: 'open' | 'closed';\n author?: string;\n authorTrusted: boolean;\n };\n note?: {\n id: number;\n body?: string;\n url?: string;\n author?: string;\n createdAt?: string;\n updatedAt?: string;\n };\n mergeRequest?: {\n number: number;\n sourceKey: string;\n title: string;\n url: string;\n createdAt?: string;\n state: 'open' | 'closed';\n draft: boolean;\n merged: boolean;\n assignees?: string[];\n reviewers?: string[];\n labels?: string[];\n labelColors?: Record<string, string>;\n author?: string;\n authorTrusted: boolean;\n factoryAuthored: boolean;\n headBranch: string;\n baseBranch: string;\n };\n}\n\nexport interface FactoryLinearRuleContext extends FactoryRuleContextBase {\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Bound board for the source this issue came from, when one is configured and installed. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryLinearEventName;\n issue: {\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n creator: string | null;\n team: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n sourceId?: string | null;\n projectId?: string | null;\n };\n}\n\nexport interface FactoryJiraRuleContext extends FactoryRuleContextBase {\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Bound board for the source this issue came from, when one is configured and installed. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryJiraEventName;\n issue: {\n /** Stable issue reference — the direct integration's Jira id or the Platform-encoded issue reference. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n author: string | null;\n project: string | null;\n site: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n };\n}\n\nexport interface FactoryIncidentioRuleContext extends FactoryRuleContextBase {\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Bound board for the source this follow-up came from, when one is configured and installed. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryIncidentioEventName;\n issue: {\n /** Stable item reference — the prefixed incident.io follow-up id the intake feed serves as `id`. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n author: string | null;\n /** Reference of the incident this follow-up belongs to, when available. */\n incident: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n };\n}\n\nexport type FactoryRuleHandler<TContext> = (\n context: Readonly<TContext>,\n) => FactoryRuleDecision | void | Promise<FactoryRuleDecision | void>;\n\nexport interface FactoryBoardRuleLeaf {\n onEnter?: FactoryRuleHandler<FactoryStageRuleContext>;\n onExit?: FactoryRuleHandler<FactoryStageRuleContext>;\n}\n\nexport type FactoryRuleRejectionCode =\n | 'forbidden'\n | 'invalid_transition'\n | 'missing_binding'\n | 'stale'\n | 'timeout'\n | 'rule_error'\n | 'causal_depth_exceeded'\n | 'repeated_transition'\n | 'approval_required';\n\nexport interface FactoryRuleRejectDecision {\n type: 'reject';\n code: FactoryRuleRejectionCode;\n reason: string;\n}\n\ninterface FactoryCommitDecisionBase {\n idempotencyKey: string;\n}\n\nexport interface FactoryTransitionDecision extends FactoryCommitDecisionBase {\n type: 'transition';\n board: FactoryRuleBoard;\n stage: FactoryRuleStage;\n /**\n * Delivered to the item's active session (waking it if idle) after the\n * transition commits. Skipped when the item has no active run binding, so\n * informational messages never fail the transition.\n */\n message?: { text: string; role?: string };\n /**\n * Runs the stage's entry rules even when the item is already in that stage.\n * A transition to the current stage is normally inert, because most callers\n * are correcting a board into a state it already holds. Re-entry is for the\n * opposite case: the stage's work is in flight and has been invalidated, so\n * it has to start over.\n */\n reenter?: boolean;\n}\n\nexport interface FactoryUpsertLinkedWorkItemDecision extends FactoryCommitDecisionBase {\n type: 'upsertLinkedWorkItem';\n board: FactoryRuleBoard;\n source: WorkItemSource;\n sourceKey: string;\n title: string;\n url: string | null;\n stage: FactoryRuleStage;\n /**\n * File the card at `stage` as its first entry and run none of the board's\n * phase rules for it — no arrival, no destination entry. The card is filed\n * (or, if it already exists, moved) and left parked for a person; nothing is\n * started for it. For external records that arrive already past the board's\n * first step: a GitHub issue whose triage is already recorded, for instance.\n *\n * Placement is the whole decision. An existing card it reaches is moved to\n * that stage through the same relocation the label routes use, and its\n * metadata is left alone.\n */\n skipRules?: boolean;\n metadata?: Record<string, FactoryRuleJsonValue>;\n}\n\ninterface FactoryInvokeSkillDecisionBase extends FactoryCommitDecisionBase {\n type: 'invokeSkill';\n role: string;\n arguments?: string;\n precedingMessage?: string;\n cancelInFlight?: boolean;\n /**\n * Start this run even when the card was moved by the agent already running in\n * this role's session. The prompt is queued onto that agent's run, so a phase\n * that shares its context with the one before it still gets its own work.\n * Without it, an agent's own move into a phase of its role starts nothing.\n */\n startsAfterOwnMove?: boolean;\n}\n\n/**\n * Starting an agent run. Most runs activate a skill, because the skill carries\n * the handoff contract later rules match on. A run whose completion is already\n * signalled some other way — Building finishes by opening a pull request, which\n * arrives as its own event — needs no contract, so it can carry a plain prompt\n * instead of an otherwise empty skill.\n */\nexport type FactoryInvokeSkillDecision = FactoryInvokeSkillDecisionBase &\n (\n | {\n skillName: string;\n prompt?: never;\n /**\n * Same-stage re-entry: the skill is already active in the card's live session,\n * so deliver a compact continuation that references it by name and carries only\n * the fresh arguments, instead of re-pasting the whole skill document. Only valid\n * for named-skill decisions — a plain prompt run has no active skill to resume.\n */\n resume?: boolean;\n }\n | { prompt: string; skillName?: never; resume?: never }\n );\n\nexport interface FactorySendMessageDecision extends FactoryCommitDecisionBase {\n type: 'sendMessage';\n /** Omitted: the card's live session, whichever seat holds it. Required with `prepareBinding`. */\n role?: string;\n message: string;\n priority?: 'medium' | 'high' | 'urgent';\n idleBehavior?: 'persist' | 'wake';\n prepareBinding?: boolean;\n}\n\nexport interface FactoryNotifyDecision extends FactoryCommitDecisionBase {\n type: 'notify';\n title: string;\n body?: string;\n level?: 'info' | 'warning' | 'error';\n}\n\n/**\n * Dismisses Factory change requests an approval has superseded on a GitHub\n * pull request. Only reviews carrying Factory's `Verdict: request changes`\n * marker from an identity other than the approving one are dismissed.\n */\nexport interface FactoryDismissStaleReviewsDecision extends FactoryCommitDecisionBase {\n type: 'dismissStaleReviews';\n installationId: number;\n repository: string;\n pullRequestNumber: number;\n approvingReviewId: string;\n approvingAuthor: string;\n}\n\nexport type FactoryCommitDecision =\n | FactoryTransitionDecision\n | FactoryDismissStaleReviewsDecision\n | FactoryUpsertLinkedWorkItemDecision\n | FactoryInvokeSkillDecision\n | FactorySendMessageDecision\n | FactoryNotifyDecision;\n\nexport type FactoryRuleDecision = FactoryRuleRejectDecision | FactoryCommitDecision;\n\nexport interface FactoryTransitionResultAccepted {\n status: 'accepted';\n transitionId: string;\n itemId: string;\n revision: number;\n stage: FactoryRuleStage;\n decisions: FactoryCommitDecision[];\n}\n\nexport interface FactoryTransitionResultRejected {\n status: 'rejected';\n transitionId: string;\n itemId: string;\n code: FactoryRuleRejectionCode;\n reason: string;\n}\n\nexport type FactoryTransitionResult = FactoryTransitionResultAccepted | FactoryTransitionResultRejected;\n\nexport function factoryRuleSourceForWorkItem(source: WorkItemSource): FactoryRuleSource {\n switch (source) {\n case 'github-issue':\n return 'issue';\n case 'github-pr':\n return 'pullRequest';\n case 'gitlab-issue':\n return 'gitlabIssue';\n case 'gitlab-pr':\n return 'gitlabPullRequest';\n case 'linear-issue':\n return 'linearIssue';\n case 'jira-issue':\n return 'jiraIssue';\n case 'incidentio-follow-up':\n return 'incidentioFollowUp';\n case 'manual':\n return 'manual';\n }\n}\n"],"mappings":";AAaA,SAAgB,0BACd,QACA,WACA,KACwB;CACxB,MAAM,CAAC,eAAe,QACpB,WAAW,cACP,CAAC,UAAU,cAAc,IACzB,WAAW,iBACT,CAAC,UAAU,OAAO,IAClB,WAAW,cACT,CAAC,UAAU,cAAc,IACzB,WAAW,iBACT,CAAC,UAAU,OAAO,IAClB,WAAW,iBACT,CAAC,UAAU,OAAO,IAClB,WAAW,eACT,CAAC,QAAQ,OAAO,IAChB,WAAW,yBACT,CAAC,cAAc,OAAO,IACtB,CAAC,WAAW,QAAQ;CACtC,OAAO;EAAE;EAAe;EAAM,YAAY;EAAW,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;CAAG;AAC/E;;AAGA,MAAa,uBAAuB;AACpC,MAAa,qBAAqB;AAI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T,KAAK,UACH,OAAO;CACX;AACF"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/rules/types.ts"],"sourcesContent":["import type { ActivityEvent, BoardEventFacts } from '../boards/board-events.js';\nimport type { ExternalWorkItemSource } from '../storage/domains/work-items/base.js';\nimport type { WorkItemRow } from '../storage/domains/work-items/work-item-schema.js';\n\nexport type WorkItemSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'manual';\n\nexport function externalSourceForWorkItem(\n source: WorkItemSource,\n sourceKey: string,\n url?: string,\n): ExternalWorkItemSource {\n const [integrationId, type] =\n source === 'github-pr'\n ? ['github', 'pull-request']\n : source === 'github-issue'\n ? ['github', 'issue']\n : source === 'gitlab-pr'\n ? ['gitlab', 'pull-request']\n : source === 'gitlab-issue'\n ? ['gitlab', 'issue']\n : source === 'linear-issue'\n ? ['linear', 'issue']\n : source === 'jira-issue'\n ? ['jira', 'issue']\n : source === 'incidentio-follow-up'\n ? ['incidentio', 'issue']\n : ['factory', 'manual'];\n return { integrationId, type, externalId: sourceKey, ...(url ? { url } : {}) };\n}\n\n/** The source label that holds an issue at rest until a maintainer decides; compared lowercased. */\nexport const NEEDS_APPROVAL_LABEL = 'status: needs approval';\n\n/** Request-changes rounds from self-review before the card parks in Intake for a person. */\nexport const SELF_REVIEW_ROUND_LIMIT = 3;\nexport const AUTO_TRIAGED_LABEL = 'status: auto-triaged';\n\n// The label only holds a card nobody accepted yet (`awaitsAcceptance`, see the boards'\n// `awaitsAcceptance`): once a person moves it into a working lane, the label is stale until the\n// source catches up (Factory removes it on that move).\nexport function needsApproval(\n item: { workItem: Pick<WorkItemRow, 'labels'>; stages?: readonly string[] },\n awaitsAcceptance: (stage: string) => boolean,\n): boolean {\n const labels = item.workItem.labels;\n if (!Array.isArray(labels)) return false;\n return (\n labels.some(label => typeof label === 'string' && label.toLowerCase() === NEEDS_APPROVAL_LABEL) &&\n (item.stages ?? []).every(awaitsAcceptance)\n );\n}\n\nexport function workItemSource(source: ExternalWorkItemSource | null): WorkItemSource {\n if (!source) return 'manual';\n if (source.integrationId === 'linear') return 'linear-issue';\n if (source.integrationId === 'gitlab') return source.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n if (source.integrationId === 'jira') return 'jira-issue';\n if (source.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io have provider-specific\n // rules; anything else (a Slack thread, say) is a plain work item, not a\n // mislabeled GitHub issue.\n if (source.integrationId !== 'github') return 'manual';\n return source.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\n/** The card's author is inside the write-access circle, or the card is Factory's own PR. */\nexport function authorTrusted(metadata: Record<string, unknown> | null | undefined): boolean {\n return metadata?.authorTrusted === true || metadata?.factoryAuthored === true;\n}\n\n// Authored outside the write-access circle: a missing trust stamp fails closed until\n// the reconcile sweep backfills it, and Factory's own PRs pass through `factoryAuthored`.\nexport function externallyAuthored(item: { source: string; metadata: Record<string, unknown> | null }): boolean {\n if (!['github-pr', 'github-issue', 'gitlab-pr', 'gitlab-issue'].includes(item.source)) return false;\n return !authorTrusted(item.metadata);\n}\n\nexport function externallyAuthoredWorkItem(item: {\n externalSource: ExternalWorkItemSource | null;\n metadata: Record<string, unknown> | null;\n}): boolean {\n return externallyAuthored({ source: workItemSource(item.externalSource), metadata: item.metadata });\n}\n\n/** A phase key on the card's board. Boards name their own phases; Factory reads none of them by name. */\nexport type FactoryRuleStage = string;\n\nexport const FACTORY_TRIAGE_TYPES = [\n 'bug',\n 'feature request',\n 'docs',\n 'question/support',\n 'maintenance',\n 'duplicate',\n 'resolved',\n 'invalid',\n 'spam',\n 'out-of-scope',\n 'other',\n] as const;\nexport type FactoryTriageType = (typeof FACTORY_TRIAGE_TYPES)[number];\n\nexport function isFactoryTriageType(value: unknown): value is FactoryTriageType {\n return typeof value === 'string' && FACTORY_TRIAGE_TYPES.some(type => type === value);\n}\n\n/** A board id. */\nexport type FactoryRuleBoard = string;\n\nexport const FACTORY_RULE_SOURCES = [\n 'issue',\n 'pullRequest',\n 'gitlabIssue',\n 'gitlabPullRequest',\n 'linearIssue',\n 'jiraIssue',\n 'incidentioFollowUp',\n 'manual',\n] as const;\nexport type FactoryRuleSource = (typeof FACTORY_RULE_SOURCES)[number];\n\nexport const FACTORY_GITHUB_EVENTS = [\n 'issueOpened',\n 'issueEdited',\n 'issueClosed',\n 'issueReopened',\n 'issueCommentCreated',\n 'issueCommentEdited',\n 'issueCommentDeleted',\n 'pullRequestOpened',\n 'pullRequestUpdated',\n 'pullRequestCommentCreated',\n 'pullRequestReviewRequested',\n 'pullRequestReviewSubmitted',\n 'pullRequestMerged',\n 'pullRequestClosed',\n] as const;\nexport type FactoryGithubEventName = (typeof FACTORY_GITHUB_EVENTS)[number];\n\nexport const FACTORY_GITLAB_EVENTS = [\n 'issueOpened',\n 'issueUpdated',\n 'issueClosed',\n 'issueReopened',\n 'issueCommented',\n 'mergeRequestOpened',\n 'mergeRequestUpdated',\n 'mergeRequestCommented',\n 'mergeRequestMerged',\n 'mergeRequestClosed',\n] as const;\nexport type FactoryGitLabEventName = (typeof FACTORY_GITLAB_EVENTS)[number];\n\nexport const FACTORY_LINEAR_EVENTS = ['issueObserved', 'issueClosed'] as const;\nexport type FactoryLinearEventName = (typeof FACTORY_LINEAR_EVENTS)[number];\n\nexport const FACTORY_JIRA_EVENTS = ['issueObserved', 'issueClosed'] as const;\nexport type FactoryJiraEventName = (typeof FACTORY_JIRA_EVENTS)[number];\n\nexport const FACTORY_INCIDENTIO_EVENTS = ['followUpObserved', 'followUpClosed'] as const;\nexport type FactoryIncidentioEventName = (typeof FACTORY_INCIDENTIO_EVENTS)[number];\n\nexport type FactoryRuleJsonValue =\n | null\n | boolean\n | number\n | string\n | FactoryRuleJsonValue[]\n | { [key: string]: FactoryRuleJsonValue };\n\nexport interface FactoryRuleItemContext {\n workItem: WorkItemRow;\n id: string;\n source: WorkItemSource;\n sourceKey: string | null;\n parentWorkItemId: string | null;\n title: string;\n url: string | null;\n stages: readonly string[];\n /**\n * @deprecated Factory no longer records triage acceptance; this is the value stamped on older\n * cards, and `null` for every card since. A person moving the card on is the approval.\n */\n acceptedAt: Date | null;\n /** Factory-owned process state and trust stamps. */\n metadata: Record<string, unknown> | null;\n}\n\nexport type FactoryRuleActor =\n | { type: 'human'; id: string }\n | { type: 'agent'; bindingId: string; role: string }\n | { type: 'github'; login: string; trusted: boolean; factoryAuthored: boolean }\n | { type: 'gitlab'; username: string; trusted: boolean; factoryAuthored: boolean }\n | { type: 'system'; id: string };\n\nexport interface FactoryRuleIngressIdentity {\n type: 'human' | 'agent' | 'toolResult' | 'github' | 'gitlab' | 'linear' | 'jira' | 'incidentio' | 'rule';\n id: string;\n}\n\nexport interface FactoryRuleCausalEntry {\n ingressId: string;\n decisionType: FactoryCommitDecision['type'];\n}\n\n/** The phase a card sits in, as its board declares it. */\nexport interface FactoryRulePhaseContext {\n id: string;\n kind: 'resting' | 'working' | 'terminal';\n /** Session context a working phase runs in; absent for resting and terminal phases. */\n context?: string;\n /** @deprecated Use `context`. */\n role?: string;\n /** Phases the card may move to from here. */\n nextPhases: readonly string[];\n}\n\nexport interface FactoryRuleContextBase {\n tenant: { orgId: string; projectId: string };\n actor: FactoryRuleActor;\n ingress: FactoryRuleIngressIdentity;\n cause: string;\n causalChain: readonly FactoryRuleCausalEntry[];\n configVersion: string;\n}\n\nexport interface FactoryBoundRuleContext extends FactoryRuleContextBase {\n item: FactoryRuleItemContext;\n board: FactoryRuleBoard;\n itemRevision: number;\n}\n\nexport interface FactoryStageRuleContext extends FactoryBoundRuleContext {\n source: FactoryRuleSource;\n stage: FactoryRuleStage;\n fromStage: FactoryRuleStage;\n toStage: FactoryRuleStage;\n}\n\nexport interface FactoryToolResultRuleContext extends FactoryBoundRuleContext {\n toolName: string;\n threadId: string;\n assistantMessageId: string;\n toolCallId: string;\n result: {\n status: 'success' | 'error';\n value: FactoryRuleJsonValue;\n };\n}\n\nexport interface FactoryGithubRuleContext extends FactoryRuleContextBase {\n /** The status change this delivery reports, named the same for every provider; absent for other events. */\n boardEvent?: BoardEventFacts;\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** The phases the card's board runs its pull request loop through; absent without a card. */\n flow?: FactoryRuleBoardFlow;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Where a new card is filed before the project's intake routes place it. */\n intake?: FactoryRuleIntakeTarget;\n /**\n * Set on the one evaluation per pull request delivery that files the pull\n * request's own Review card. Opening a pull request concerns two cards — that\n * Review card and the Work item that authored the pull request — so the rule\n * answers for the two separately: the arrival carries this flag and is\n * committed against the authoring item when resolution found one, which is\n * what links the new card to it, while the authoring item's own evaluation\n * leaves the flag unset.\n */\n pullRequestIntake?: boolean;\n /**\n * Set on both evaluations of a pull request's first sighting when it belongs on an existing\n * card: the Work card that authored it (`authored`), or the card of the issue a trusted author's\n * pull request says it closes (`closes`). The pull request is filed on that card as one more\n * source rather than on a card of its own.\n */\n pullRequestHome?: FactoryPullRequestHome;\n event: FactoryGithubEventName;\n deliveryId: string;\n factory: { createdAt: string };\n /** `installationId` is the GitHub App installation the delivery arrived through. */\n repository: { id: number; fullName: string; installationId?: number };\n issue?: {\n number: number;\n title: string;\n url: string;\n createdAt?: string;\n updatedAt?: string;\n assignees?: string[];\n labels?: string[];\n state?: 'open' | 'closed';\n author?: string;\n /** GitHub close reason: `completed`, `not_planned`, or `duplicate`. */\n stateReason?: string;\n };\n issueChange?: { title: boolean; body: boolean };\n issueComment?: {\n id: number;\n body?: string;\n url?: string;\n author?: string;\n authorType?: string;\n createdAt?: string;\n updatedAt?: string;\n };\n pullRequest?: {\n number: number;\n title: string;\n url: string;\n createdAt?: string;\n state: 'open' | 'closed';\n draft: boolean;\n merged: boolean;\n assignees?: string[];\n requestedReviewers?: string[];\n labels?: string[];\n author?: string;\n factoryAuthored: boolean;\n headBranch: string;\n /** Lowercase head commit SHA, when the delivery carries one. */\n headSha?: string;\n baseBranch: string;\n };\n /** Present on `pullRequestReviewRequested`: who review was (re-)requested from. */\n reviewRequest?: { reviewer: string; factoryReviewer: boolean };\n /** Present when a PR comment uses Factory's exact review command. */\n reviewCommand?: { command: 'review' | 're-review'; target: string };\n /**\n * Present on `pullRequestReviewSubmitted`: the review that was just posted, or a\n * request-changes review whose body was edited to a new Factory verdict.\n */\n review?: { id: number; state: string; url: string; author?: string; body?: string };\n}\n\n/**\n * Where an integration files a new card: the default board's initial phase. The project's intake\n * routes then decide where the card goes; the board and phase a rule names don't. Absent when the\n * default board is not installed.\n */\nexport interface FactoryRuleIntakeTarget {\n board: string;\n initialPhase: string;\n}\n\n/**\n * Where a source-closed rule moves the card, from the `sourceClosed` mapping its installed board\n * declares. Absent when the card's board is not installed or declares no mapping.\n */\nexport interface FactoryRuleBoardClosure {\n /** Title of the card's board, for messages. */\n boardTitle: string;\n /** Terminal phase for a source that was completed. */\n completed: FactoryRuleBoardClosurePhase;\n /** Terminal phase for a source that was canceled or not planned. */\n canceled: FactoryRuleBoardClosurePhase;\n /** Whether the card already sits in a terminal phase of its board. */\n itemTerminal: boolean;\n}\n\nexport interface FactoryRuleBoardClosurePhase {\n phase: string;\n title: string;\n}\n\n/**\n * The phases a card's board runs its pull request loop through, read from what each phase declares\n * (see `boardFlow`). Every field is absent when the board has no such phase.\n */\nexport interface FactoryRuleBoardFlow {\n /** Where a card on the board rests before work starts and goes back to when its pull request is abandoned. */\n readonly initialPhase?: string;\n /** Phase that takes pull requests: reviews them, records verdicts on them, and re-reviews pushes. */\n readonly pullRequestReview?: string;\n /** Working phase that sorts new cards before anyone accepts them: on a board that builds, the first one that neither builds nor reviews. */\n readonly triage?: string;\n /** Working phase that reviews the builder's branch before a pull request opens. */\n readonly selfReview?: string;\n /** Working phase that builds the change and opens the pull request. */\n readonly build?: string;\n /** Seat that runs {@link build}; pull request feedback wakes it. */\n readonly buildRole?: string;\n /** Terminal phase a merge finishes the card in: the board's `sourceClosed.completed`, else its first terminal phase. */\n readonly completed?: Readonly<FactoryRuleBoardClosurePhase>;\n /** Terminal phase a pull request closed unmerged ends its own card in: `sourceClosed.canceled`, else the next terminal phase. */\n readonly canceled?: Readonly<FactoryRuleBoardClosurePhase>;\n}\n\nexport interface FactoryGitLabRuleContext extends FactoryRuleContextBase {\n /** The status change this delivery reports, named the same for every provider; absent for other events. */\n boardEvent?: BoardEventFacts;\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** The phases the card's board runs its pull request loop through; absent without a card. */\n flow?: FactoryRuleBoardFlow;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n intake?: FactoryRuleIntakeTarget;\n /** Set on a merge request's first sighting when it is filed on an existing card instead of its own. */\n pullRequestHome?: FactoryPullRequestHome;\n event: FactoryGitLabEventName;\n deliveryId: string;\n factory: { createdAt: string };\n repository: { id: number; fullName: string; host: string };\n issue?: {\n number: number;\n sourceKey: string;\n title: string;\n url: string;\n createdAt?: string;\n updatedAt?: string;\n assignees?: string[];\n labels?: string[];\n labelColors?: Record<string, string>;\n state?: 'open' | 'closed';\n author?: string;\n authorTrusted: boolean;\n };\n note?: {\n id: number;\n body?: string;\n url?: string;\n author?: string;\n createdAt?: string;\n updatedAt?: string;\n };\n mergeRequest?: {\n number: number;\n sourceKey: string;\n title: string;\n url: string;\n createdAt?: string;\n state: 'open' | 'closed';\n draft: boolean;\n merged: boolean;\n assignees?: string[];\n reviewers?: string[];\n labels?: string[];\n labelColors?: Record<string, string>;\n author?: string;\n authorTrusted: boolean;\n factoryAuthored: boolean;\n headBranch: string;\n baseBranch: string;\n };\n}\n\nexport interface FactoryLinearRuleContext extends FactoryRuleContextBase {\n /** The status change this delivery reports, named the same for every provider; absent for other events. */\n boardEvent?: BoardEventFacts;\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** The phases the card's board runs its pull request loop through; absent without a card. */\n flow?: FactoryRuleBoardFlow;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Where a new card is filed before the project's intake routes place it. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryLinearEventName;\n issue: {\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n creator: string | null;\n team: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n sourceId?: string | null;\n projectId?: string | null;\n };\n}\n\nexport interface FactoryJiraRuleContext extends FactoryRuleContextBase {\n /** The status change this delivery reports, named the same for every provider; absent for other events. */\n boardEvent?: BoardEventFacts;\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** The phases the card's board runs its pull request loop through; absent without a card. */\n flow?: FactoryRuleBoardFlow;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Where a new card is filed before the project's intake routes place it. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryJiraEventName;\n issue: {\n /** Stable issue reference — the direct integration's Jira id or the Platform-encoded issue reference. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n author: string | null;\n project: string | null;\n site: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n };\n}\n\nexport interface FactoryIncidentioRuleContext extends FactoryRuleContextBase {\n /** The status change this delivery reports, named the same for every provider; absent for other events. */\n boardEvent?: BoardEventFacts;\n item?: FactoryRuleItemContext;\n board?: FactoryRuleBoard;\n itemRevision?: number;\n /** Where the card's board sends it when its tracked source closes. */\n boardClosure?: FactoryRuleBoardClosure;\n /** The phases the card's board runs its pull request loop through; absent without a card. */\n flow?: FactoryRuleBoardFlow;\n /** What the card's current phase means on its board; absent without a card or when the board does not declare the phase. */\n phase?: FactoryRulePhaseContext;\n /** Where a new card is filed before the project's intake routes place it. */\n intake?: FactoryRuleIntakeTarget;\n event: FactoryIncidentioEventName;\n issue: {\n /** Stable item reference — the prefixed incident.io follow-up id the intake feed serves as `id`. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n author: string | null;\n /** Reference of the incident this follow-up belongs to, when available. */\n incident: string | null;\n labels: readonly string[];\n createdAt: string;\n updatedAt: string;\n };\n}\n\nexport type FactoryRuleHandler<TContext> = (\n context: Readonly<TContext>,\n) => FactoryRuleDecision | void | Promise<FactoryRuleDecision | void>;\n\nexport type FactoryRuleRejectionCode =\n | 'forbidden'\n | 'invalid_transition'\n | 'missing_binding'\n | 'stale'\n | 'timeout'\n | 'rule_error'\n | 'causal_depth_exceeded'\n | 'repeated_transition'\n | 'approval_required';\n\nexport interface FactoryRuleRejectDecision {\n type: 'reject';\n code: FactoryRuleRejectionCode;\n reason: string;\n}\n\ninterface FactoryCommitDecisionBase {\n idempotencyKey: string;\n}\n\nexport interface FactoryTransitionDecision extends FactoryCommitDecisionBase {\n type: 'transition';\n board: FactoryRuleBoard;\n stage: FactoryRuleStage;\n /**\n * Delivered to the item's active session (waking it if idle) after the\n * transition commits. Skipped when the item has no active run binding, so\n * informational messages never fail the transition.\n */\n message?: { text: string; role?: string };\n /**\n * Runs the stage's entry rules even when the item is already in that stage.\n * A transition to the current stage is normally inert, because most callers\n * are correcting a board into a state it already holds. Re-entry is for the\n * opposite case: the stage's work is in flight and has been invalidated, so\n * it has to start over.\n */\n reenter?: boolean;\n /**\n * The status event this move answers. The project's intake routes on the card's board then\n * decide where the card goes instead, and this move applies only when no route on the board\n * handles the event; a route that does, even a disabled one, owns it. Factory drops the tag\n * from a decision returned by an explicit override on the integration's `rules`, so that\n * override's move always applies; a board handler's tagged move still goes to the routes.\n */\n event?: BoardEventFacts;\n}\n\n/**\n * Hands a status event on an existing card to the project's intake routes: the first enabled\n * route on the card's board whose `on` names the event and whose `when` matches moves the card.\n * Integrations add it when no rule decided anything for the delivery; nothing moves when no\n * route matches.\n */\nexport interface FactoryRouteEventDecision extends FactoryCommitDecisionBase {\n type: 'routeEvent';\n event: BoardEventFacts;\n}\n\n/**\n * Tells the card's live session that its source saw activity, such as a new\n * comment or an edit. It carries pointers only: the dispatcher writes the\n * message from these fields, so no provider text (a comment body, a title)\n * ever reaches the session through it. Without a live session it is dropped.\n */\nexport interface FactorySignalActivityDecision extends FactoryCommitDecisionBase {\n type: 'signalActivity';\n event: ActivityEvent;\n /** The source's own reference, such as `acme/app#12`. */\n reference: string;\n url: string;\n author?: string;\n authorTrusted: boolean;\n /**\n * What an idle session does with it. Defaults to `wake`; `persist` leaves it\n * in the session's notifications without starting a run, for sources whose\n * own comments Factory cannot tell apart from other people's. Activity from an\n * untrusted author always persists.\n */\n idleBehavior?: 'wake' | 'persist';\n}\n\n/** The existing card a pull or merge request is filed on; see `pullRequestHome`. */\nexport interface FactoryPullRequestHome {\n workItemId: string;\n reason: 'authored' | 'closes';\n}\n\nexport interface FactoryUpsertLinkedWorkItemDecision extends FactoryCommitDecisionBase {\n type: 'upsertLinkedWorkItem';\n board: FactoryRuleBoard;\n source: WorkItemSource;\n sourceKey: string;\n title: string;\n url: string | null;\n stage: FactoryRuleStage;\n /**\n * File the card at `stage` as its first entry and run none of the board's\n * phase rules for it — no arrival, no destination entry. The card is filed\n * (or, if it already exists, moved) and left parked for a person; nothing is\n * started for it. For external records that arrive already past the board's\n * first step: a GitHub issue whose triage is already recorded, for instance.\n *\n * Placement is the whole decision. An existing card it reaches is moved to\n * that stage through the same relocation the label routes use, and its\n * metadata is left alone.\n */\n skipRules?: boolean;\n /**\n * File the pull or merge request on this existing card, the one that authored it, as one more\n * source instead of on a card of its own. Applies only when no card holds the record yet and\n * the card is still open on Work; otherwise the record is filed as usual.\n */\n attachTo?: { workItemId: string };\n /**\n * The card of the issue this pull or merge request closes. When no card holds the record yet,\n * the project's intake routes can test that card and join the record to it (see\n * `IntakeRouteTarget.joinClosedIssue`); otherwise it is filed as usual.\n */\n closesIssue?: { workItemId: string };\n metadata?: Record<string, FactoryRuleJsonValue>;\n}\n\ninterface FactoryInvokeSkillDecisionBase extends FactoryCommitDecisionBase {\n type: 'invokeSkill';\n role: string;\n arguments?: string;\n precedingMessage?: string;\n cancelInFlight?: boolean;\n /**\n * Start this run even when the card was moved by the agent already running in\n * this role's session. The prompt is queued onto that agent's run, so a phase\n * that shares its context with the one before it still gets its own work.\n * Without it, an agent's own move into a phase of its role starts nothing.\n */\n startsAfterOwnMove?: boolean;\n /**\n * Pursue the run's work as a goal: the session's thread holds `objective` until the card\n * leaves the phase, and the agent's goal judge keeps the run going until it is met.\n */\n goal?: { objective: string; maxRuns?: number };\n}\n\n/**\n * Starting an agent run. Most runs activate a skill, because the skill carries\n * the handoff contract later rules match on. A run whose completion is already\n * signalled some other way — Building finishes by opening a pull request, which\n * arrives as its own event — needs no contract, so it can carry a plain prompt\n * instead of an otherwise empty skill.\n */\nexport type FactoryInvokeSkillDecision = FactoryInvokeSkillDecisionBase &\n (\n | {\n skillName: string;\n prompt?: never;\n /**\n * Same-stage re-entry: the skill is already active in the card's live session,\n * so deliver a compact continuation that references it by name and carries only\n * the fresh arguments, instead of re-pasting the whole skill document. Only valid\n * for named-skill decisions — a plain prompt run has no active skill to resume.\n */\n resume?: boolean;\n }\n | { prompt: string; skillName?: never; resume?: never }\n );\n\nexport interface FactorySendMessageDecision extends FactoryCommitDecisionBase {\n type: 'sendMessage';\n /** Omitted: the card's live session, whichever seat holds it. Required with `prepareBinding`. */\n role?: string;\n message: string;\n priority?: 'medium' | 'high' | 'urgent';\n idleBehavior?: 'persist' | 'wake';\n prepareBinding?: boolean;\n}\n\nexport interface FactoryNotifyDecision extends FactoryCommitDecisionBase {\n type: 'notify';\n title: string;\n body?: string;\n level?: 'info' | 'warning' | 'error';\n}\n\n/**\n * Dismisses Factory change requests an approval has superseded on a GitHub\n * pull request. Only reviews carrying Factory's `Verdict: request changes`\n * marker from an identity other than the approving one are dismissed.\n */\nexport interface FactoryDismissStaleReviewsDecision extends FactoryCommitDecisionBase {\n type: 'dismissStaleReviews';\n installationId: number;\n repository: string;\n pullRequestNumber: number;\n approvingReviewId: string;\n approvingAuthor: string;\n}\n\nexport type FactoryCommitDecision =\n | FactoryTransitionDecision\n | FactoryRouteEventDecision\n | FactorySignalActivityDecision\n | FactoryDismissStaleReviewsDecision\n | FactoryUpsertLinkedWorkItemDecision\n | FactoryInvokeSkillDecision\n | FactorySendMessageDecision\n | FactoryNotifyDecision;\n\nexport type FactoryRuleDecision = FactoryRuleRejectDecision | FactoryCommitDecision;\n\nexport interface FactoryTransitionResultAccepted {\n status: 'accepted';\n transitionId: string;\n itemId: string;\n revision: number;\n stage: FactoryRuleStage;\n decisions: FactoryCommitDecision[];\n}\n\nexport interface FactoryTransitionResultRejected {\n status: 'rejected';\n transitionId: string;\n itemId: string;\n code: FactoryRuleRejectionCode;\n reason: string;\n}\n\nexport type FactoryTransitionResult = FactoryTransitionResultAccepted | FactoryTransitionResultRejected;\n\nexport function factoryRuleSourceForWorkItem(source: WorkItemSource): FactoryRuleSource {\n switch (source) {\n case 'github-issue':\n return 'issue';\n case 'github-pr':\n return 'pullRequest';\n case 'gitlab-issue':\n return 'gitlabIssue';\n case 'gitlab-pr':\n return 'gitlabPullRequest';\n case 'linear-issue':\n return 'linearIssue';\n case 'jira-issue':\n return 'jiraIssue';\n case 'incidentio-follow-up':\n return 'incidentioFollowUp';\n case 'manual':\n return 'manual';\n }\n}\n"],"mappings":";AAcA,SAAgB,0BACd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AAM,GAAG,OAAO;CAC9F,OAAO,CAAC,cAAc,KAAK,QAAQ;AACrC;AAEA,SAAgB,2BAA2B,MAG/B;CACV,OAAO,mBAAmB;EAAE,QAAQ,eAAe,KAAK,cAAc;EAAG,UAAU,KAAK;CAAS,CAAC;AACpG;AAKA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,OAAO,UAAU,YAAY,qBAAqB,MAAK,SAAQ,SAAS,KAAK;AACtF;AAKA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAa,wBAAwB,CAAC,iBAAiB,aAAa;AAGpE,MAAa,sBAAsB,CAAC,iBAAiB,aAAa;AAGlE,MAAa,4BAA4B,CAAC,oBAAoB,gBAAgB;AAqnB9E,SAAgB,6BAA6B,QAA2C;CACtF,QAAQ,QAAR;EACE,KAAK,gBACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,gBACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,gBACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,wBACH,OAAO;EACT,KAAK,UACH,OAAO;CACX;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/rules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EAGrB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAQ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_LENGTH = 128;
@@ -15,6 +16,11 @@ const MAX_METADATA_JSON_LENGTH = 16384;
15
16
  const MAX_JSON_DEPTH = 8;
16
17
  const MAX_JSON_COLLECTION_SIZE = 100;
17
18
  const MAX_BOARD_IDENTIFIER_LENGTH = 128;
19
+ /** A source reference such as `acme/app#12` or `group/sub/project#3`. */
20
+ const SOURCE_REFERENCE_RE = /^[a-z0-9_][a-z0-9_.\/-]*#\d+$/i;
21
+ /** A provider login such as `octocat`, `dependabot[bot]`, `jane.doe` or GitLab's `_jane`. */
22
+ const LOGIN_RE = /^[a-z0-9_][a-z0-9_.-]*(\[bot\])?$/i;
23
+ const MAX_LOGIN_LENGTH = 100;
18
24
  const IDENTIFIER_RE = /^[a-z0-9][a-z0-9_-]*$/i;
19
25
  const BOARD_IDENTIFIER_RE = IDENTIFIER_RE;
20
26
  const SKILL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -68,6 +74,23 @@ function boardIdentifier(value, label) {
68
74
  if (!isBoardIdentifier(value)) throw new FactoryRuleValidationError(`${label} is invalid.`);
69
75
  return value;
70
76
  }
77
+ function boardEvent(value, label) {
78
+ if (!isPlainObject(value)) throw new FactoryRuleValidationError(`${label} event must be an object.`);
79
+ assertExactKeys(value, ["type", "reason"], `${label} event`);
80
+ const type = enumValue(value.type, STATUS_EVENTS, `${label} event type`);
81
+ const reason = value.reason === void 0 ? void 0 : enumValue(value.reason, CLOSE_REASONS, `${label} event reason`);
82
+ return {
83
+ type,
84
+ ...reason ? { reason } : {}
85
+ };
86
+ }
87
+ function linkedItemReference(value, field) {
88
+ if (value === void 0) return void 0;
89
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new FactoryRuleValidationError(`Factory linked work item ${field} must be an object.`);
90
+ assertExactKeys(value, ["workItemId"], `Factory linked work item ${field}`);
91
+ const { workItemId } = value;
92
+ return { workItemId: boundedString(workItemId, `Factory linked work item ${field}.workItemId`, 128) };
93
+ }
71
94
  function assertFactoryDecisionTarget(decision, boards, itemBoard) {
72
95
  if (decision.type !== "transition" && decision.type !== "upsertLinkedWorkItem") return;
73
96
  const board = boards.get(decision.board);
@@ -75,6 +98,20 @@ function assertFactoryDecisionTarget(decision, boards, itemBoard) {
75
98
  if (!Object.hasOwn(board.phases, decision.stage)) throw new FactoryRuleValidationError("Factory decision target phase is not defined on its board.");
76
99
  if (decision.type === "transition" && itemBoard !== void 0 && itemBoard !== decision.board) throw new FactoryRuleValidationError("Factory transition cannot change the item board.");
77
100
  }
101
+ const MAX_GOAL_OBJECTIVE_LENGTH = 2e3;
102
+ const MAX_GOAL_RUNS = 50;
103
+ function invokeSkillGoal(value) {
104
+ if (value === void 0) return void 0;
105
+ if (!isPlainObject(value)) throw new FactoryRuleValidationError("Factory skill goal must be an object.");
106
+ assertExactKeys(value, ["objective", "maxRuns"], "Factory skill goal");
107
+ const objective = boundedString(value.objective, "Factory skill goal objective", MAX_GOAL_OBJECTIVE_LENGTH);
108
+ const { maxRuns } = value;
109
+ if (maxRuns !== void 0 && (typeof maxRuns !== "number" || !Number.isInteger(maxRuns) || maxRuns < 1 || maxRuns > MAX_GOAL_RUNS)) throw new FactoryRuleValidationError("Factory skill goal maxRuns is invalid.");
110
+ return {
111
+ objective,
112
+ ...maxRuns !== void 0 ? { maxRuns } : {}
113
+ };
114
+ }
78
115
  function optionalBoundedString(value, label, max) {
79
116
  if (value === void 0) return void 0;
80
117
  return boundedString(value, label, max);
@@ -149,7 +186,8 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
149
186
  "board",
150
187
  "stage",
151
188
  "message",
152
- "reenter"
189
+ "reenter",
190
+ "event"
153
191
  ], "Factory transition decision");
154
192
  if (value.reenter !== void 0 && typeof value.reenter !== "boolean") throw new FactoryRuleValidationError("Factory transition reenter must be a boolean.");
155
193
  let message;
@@ -168,7 +206,45 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
168
206
  board: boardIdentifier(value.board, "Factory transition board"),
169
207
  stage: boardIdentifier(value.stage, "Factory transition stage"),
170
208
  ...message ? { message } : {},
171
- ...value.reenter === true ? { reenter: true } : {}
209
+ ...value.reenter === true ? { reenter: true } : {},
210
+ ...value.event !== void 0 ? { event: boardEvent(value.event, "Factory transition") } : {}
211
+ };
212
+ }
213
+ case "routeEvent":
214
+ assertExactKeys(value, [
215
+ "type",
216
+ "idempotencyKey",
217
+ "event"
218
+ ], "Factory routeEvent decision");
219
+ return {
220
+ type,
221
+ ...commonCommitFields(value),
222
+ event: boardEvent(value.event, "Factory routeEvent")
223
+ };
224
+ case "signalActivity": {
225
+ assertExactKeys(value, [
226
+ "type",
227
+ "idempotencyKey",
228
+ "event",
229
+ "reference",
230
+ "url",
231
+ "author",
232
+ "authorTrusted",
233
+ "idleBehavior"
234
+ ], "Factory signalActivity decision");
235
+ const url = value.url;
236
+ if (typeof url !== "string" || url.length > MAX_URL_LENGTH || !/^https?:\/\/\S+$/.test(url)) throw new FactoryRuleValidationError("Factory signalActivity url must be an http(s) URL.");
237
+ if (typeof value.authorTrusted !== "boolean") throw new FactoryRuleValidationError("Factory signalActivity authorTrusted must be a boolean.");
238
+ const author = value.author === void 0 ? void 0 : boundedString(value.author, "Factory signalActivity author", MAX_LOGIN_LENGTH, LOGIN_RE);
239
+ return {
240
+ type,
241
+ ...commonCommitFields(value),
242
+ event: enumValue(value.event, ACTIVITY_EVENTS, "Factory signalActivity event"),
243
+ reference: boundedString(value.reference, "Factory signalActivity reference", MAX_SOURCE_KEY_LENGTH, SOURCE_REFERENCE_RE),
244
+ url,
245
+ ...author ? { author } : {},
246
+ authorTrusted: value.authorTrusted,
247
+ ...value.idleBehavior === void 0 ? {} : { idleBehavior: enumValue(value.idleBehavior, ["wake", "persist"], "Factory signalActivity idleBehavior") }
172
248
  };
173
249
  }
174
250
  case "upsertLinkedWorkItem": {
@@ -183,12 +259,16 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
183
259
  "url",
184
260
  "stage",
185
261
  "skipRules",
262
+ "attachTo",
263
+ "closesIssue",
186
264
  "metadata"
187
265
  ], "Factory linked work item decision");
188
266
  if (value.skipRules !== void 0 && typeof value.skipRules !== "boolean") throw new FactoryRuleValidationError("Factory linked work item skipRules must be a boolean.");
189
267
  const url = value.url;
190
268
  if (url !== null && (typeof url !== "string" || url.length > MAX_URL_LENGTH || !/^https?:\/\//.test(url))) throw new FactoryRuleValidationError("Factory linked work item URL is invalid.");
191
269
  const metadata = sanitizeMetadata(value.metadata);
270
+ const attachTo = linkedItemReference(value.attachTo, "attachTo");
271
+ const closesIssue = linkedItemReference(value.closesIssue, "closesIssue");
192
272
  return {
193
273
  type,
194
274
  ...commonCommitFields(value),
@@ -199,6 +279,8 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
199
279
  url,
200
280
  stage: boardIdentifier(value.stage, "Factory linked work item stage"),
201
281
  ...value.skipRules === true ? { skipRules: true } : {},
282
+ ...attachTo ? { attachTo } : {},
283
+ ...closesIssue ? { closesIssue } : {},
202
284
  ...metadata ? { metadata } : {}
203
285
  };
204
286
  }
@@ -213,7 +295,8 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
213
295
  "precedingMessage",
214
296
  "cancelInFlight",
215
297
  "startsAfterOwnMove",
216
- "resume"
298
+ "resume",
299
+ "goal"
217
300
  ], "Factory invoke skill decision");
218
301
  if (value.skillName === void 0 === (value.prompt === void 0)) throw new FactoryRuleValidationError("Factory skill invocation needs exactly one of skillName or prompt.");
219
302
  const args = optionalBoundedString(value.arguments, "Factory skill arguments", MAX_ARGUMENTS_LENGTH);
@@ -222,6 +305,7 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
222
305
  if (value.startsAfterOwnMove !== void 0 && typeof value.startsAfterOwnMove !== "boolean") throw new FactoryRuleValidationError("Factory skill startsAfterOwnMove must be a boolean.");
223
306
  if (value.resume !== void 0 && typeof value.resume !== "boolean") throw new FactoryRuleValidationError("Factory skill resume must be a boolean.");
224
307
  if (value.resume === true && value.skillName === void 0) throw new FactoryRuleValidationError("Factory skill resume requires skillName.");
308
+ const goal = invokeSkillGoal(value.goal);
225
309
  return {
226
310
  type,
227
311
  ...commonCommitFields(value),
@@ -233,7 +317,8 @@ function validateFactoryRuleDecision(value, causalDepth = 0) {
233
317
  ...args ? { arguments: args } : {},
234
318
  ...precedingMessage ? { precedingMessage } : {},
235
319
  ...value.cancelInFlight === true ? { cancelInFlight: true } : {},
236
- ...value.startsAfterOwnMove === true ? { startsAfterOwnMove: true } : {}
320
+ ...value.startsAfterOwnMove === true ? { startsAfterOwnMove: true } : {},
321
+ ...goal ? { goal } : {}
237
322
  };
238
323
  }
239
324
  case "sendMessage": {
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","names":[],"sources":["../../src/rules/validation.ts"],"sourcesContent":["import type { BoardRegistry } from '../boards/registry.js';\nimport type {\n FactoryCommitDecision,\n FactoryRuleDecision,\n FactoryRuleJsonValue,\n FactoryRuleRejectionCode,\n WorkItemSource,\n} from './types.js';\n\nexport const MAX_FACTORY_RULE_CAUSAL_DEPTH = 8;\n\nconst MAX_VERSION_LENGTH = 128;\nconst MAX_IDEMPOTENCY_KEY_LENGTH = 256;\nconst MAX_REASON_LENGTH = 512;\nconst MAX_TITLE_LENGTH = 512;\nconst MAX_MESSAGE_LENGTH = 8_192;\nconst MAX_ARGUMENTS_LENGTH = 4_096;\nexport const MAX_ROLE_LENGTH = 32;\nexport const MAX_TOOL_NAME_LENGTH = 128;\nexport const MAX_SKILL_NAME_LENGTH = 128;\nconst MAX_SOURCE_KEY_LENGTH = 256;\nconst MAX_URL_LENGTH = 2_048;\nconst MAX_METADATA_JSON_LENGTH = 16_384;\nconst MAX_JSON_DEPTH = 8;\nconst MAX_JSON_COLLECTION_SIZE = 100;\n\nexport const MAX_BOARD_IDENTIFIER_LENGTH = 128;\nexport const IDENTIFIER_RE = /^[a-z0-9][a-z0-9_-]*$/i;\nexport const BOARD_IDENTIFIER_RE = IDENTIFIER_RE;\nexport const SKILL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst SENSITIVE_KEY_RE = /(?:authorization|cookie|credential|password|secret|token)/i;\nconst WORK_ITEM_SOURCES: readonly WorkItemSource[] = [\n 'github-issue',\n 'github-pr',\n 'gitlab-issue',\n 'gitlab-pr',\n 'linear-issue',\n 'jira-issue',\n 'incidentio-follow-up',\n 'manual',\n];\nconst REJECTION_CODES: readonly FactoryRuleRejectionCode[] = [\n 'forbidden',\n 'invalid_transition',\n 'missing_binding',\n 'stale',\n 'timeout',\n 'rule_error',\n 'causal_depth_exceeded',\n 'repeated_transition',\n];\n\nexport class FactoryRuleValidationError extends Error {\n readonly code = 'invalid_factory_rule';\n\n constructor(message: string) {\n super(message);\n this.name = 'FactoryRuleValidationError';\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction assertExactKeys(value: Record<string, unknown>, keys: readonly string[], label: string): void {\n const allowed = new Set(keys);\n if (Object.keys(value).some(key => !allowed.has(key))) {\n throw new FactoryRuleValidationError(`${label} contains an unsupported field.`);\n }\n}\n\nfunction boundedString(value: unknown, label: string, max: number, pattern?: RegExp): string {\n if (typeof value !== 'string') throw new FactoryRuleValidationError(`${label} must be a string.`);\n const normalized = value.trim();\n if (normalized.length === 0 || normalized.length > max || (pattern && !pattern.test(normalized))) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return normalized;\n}\n\nexport function isBoardIdentifier(value: unknown): value is string {\n return typeof value === 'string' && value.length <= MAX_BOARD_IDENTIFIER_LENGTH && BOARD_IDENTIFIER_RE.test(value);\n}\n\nfunction boardIdentifier(value: unknown, label: string): string {\n if (!isBoardIdentifier(value)) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return value;\n}\n\nexport function assertFactoryDecisionTarget(\n decision: FactoryRuleDecision,\n boards: BoardRegistry,\n itemBoard?: string | null,\n): void {\n if (decision.type !== 'transition' && decision.type !== 'upsertLinkedWorkItem') return;\n const board = boards.get(decision.board);\n if (!board) throw new FactoryRuleValidationError('Factory decision target board is not installed.');\n if (!Object.hasOwn(board.phases, decision.stage)) {\n throw new FactoryRuleValidationError('Factory decision target phase is not defined on its board.');\n }\n if (decision.type === 'transition' && itemBoard !== undefined && itemBoard !== decision.board) {\n throw new FactoryRuleValidationError('Factory transition cannot change the item board.');\n }\n}\n\nfunction optionalBoundedString(value: unknown, label: string, max: number): string | undefined {\n if (value === undefined) return undefined;\n return boundedString(value, label, max);\n}\n\nfunction enumValue<T extends string>(value: unknown, allowed: readonly T[], label: string): T {\n if (typeof value !== 'string' || !allowed.includes(value as T)) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return value as T;\n}\n\nexport function normalizeFactoryRuleJsonValue(\n value: unknown,\n depth = 0,\n seen = new Set<object>(),\n): FactoryRuleJsonValue {\n if (value === null || typeof value === 'boolean' || typeof value === 'string') return value;\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw new FactoryRuleValidationError('Rule metadata must contain finite numbers.');\n return value;\n }\n if (depth >= MAX_JSON_DEPTH || (typeof value !== 'object' && !Array.isArray(value))) {\n throw new FactoryRuleValidationError('Rule metadata is not bounded JSON.');\n }\n if (seen.has(value as object)) throw new FactoryRuleValidationError('Rule metadata must not contain cycles.');\n seen.add(value as object);\n try {\n if (Array.isArray(value)) {\n if (value.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Rule metadata contains too many entries.');\n }\n return value.map(entry => normalizeFactoryRuleJsonValue(entry, depth + 1, seen));\n }\n if (!isPlainObject(value)) throw new FactoryRuleValidationError('Rule metadata must use plain objects.');\n const entries = Object.entries(value);\n if (entries.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Rule metadata contains too many fields.');\n }\n const sanitized: Record<string, FactoryRuleJsonValue> = {};\n for (const [key, entry] of entries) {\n const normalizedKey = boundedString(key, 'Rule metadata key', 128, IDENTIFIER_RE);\n sanitized[normalizedKey] = SENSITIVE_KEY_RE.test(normalizedKey)\n ? '[REDACTED]'\n : normalizeFactoryRuleJsonValue(entry, depth + 1, seen);\n }\n return sanitized;\n } finally {\n seen.delete(value as object);\n }\n}\n\nfunction sanitizeMetadata(value: unknown): Record<string, FactoryRuleJsonValue> | undefined {\n if (value === undefined) return undefined;\n const sanitized = normalizeFactoryRuleJsonValue(value);\n if (!isPlainObject(sanitized)) throw new FactoryRuleValidationError('Rule metadata must be an object.');\n if (JSON.stringify(sanitized).length > MAX_METADATA_JSON_LENGTH) {\n throw new FactoryRuleValidationError('Rule metadata is too large.');\n }\n return sanitized;\n}\n\nexport const DEFAULT_FACTORY_CONFIG_VERSION = 'factory-config-v1';\n\n/** Operator-maintained provenance label stamped on transition audit and deferred-decision rows. */\nexport function assertFactoryConfigVersion(value: unknown): string {\n return boundedString(value, 'Factory configVersion', MAX_VERSION_LENGTH);\n}\n\nfunction commonCommitFields(value: Record<string, unknown>): { idempotencyKey: string } {\n return {\n idempotencyKey: boundedString(value.idempotencyKey, 'Factory decision idempotencyKey', MAX_IDEMPOTENCY_KEY_LENGTH),\n };\n}\n\nexport function validateFactoryRuleDecision(value: unknown, causalDepth = 0): FactoryRuleDecision {\n if (causalDepth > MAX_FACTORY_RULE_CAUSAL_DEPTH) {\n throw new FactoryRuleValidationError('Factory rule causal depth exceeded.');\n }\n if (!isPlainObject(value)) throw new FactoryRuleValidationError('Factory rule decision must be an object.');\n const type = value.type;\n if (typeof type !== 'string') throw new FactoryRuleValidationError('Factory rule decision type is required.');\n\n switch (type) {\n case 'reject': {\n assertExactKeys(value, ['type', 'code', 'reason'], 'Factory reject decision');\n return {\n type,\n code: enumValue(value.code, REJECTION_CODES, 'Factory rejection code'),\n reason: boundedString(value.reason, 'Factory rejection reason', MAX_REASON_LENGTH),\n };\n }\n case 'transition': {\n assertExactKeys(\n value,\n ['type', 'idempotencyKey', 'board', 'stage', 'message', 'reenter'],\n 'Factory transition decision',\n );\n if (value.reenter !== undefined && typeof value.reenter !== 'boolean') {\n throw new FactoryRuleValidationError('Factory transition reenter must be a boolean.');\n }\n let message: { text: string; role?: string } | undefined;\n if (value.message !== undefined) {\n if (!isPlainObject(value.message)) {\n throw new FactoryRuleValidationError('Factory transition message must be an object.');\n }\n assertExactKeys(value.message, ['text', 'role'], 'Factory transition message');\n const role =\n value.message.role === undefined\n ? undefined\n : boundedString(value.message.role, 'Factory transition message role', MAX_ROLE_LENGTH, IDENTIFIER_RE);\n message = {\n text: boundedString(value.message.text, 'Factory transition message text', MAX_MESSAGE_LENGTH),\n ...(role ? { role } : {}),\n };\n }\n return {\n type,\n ...commonCommitFields(value),\n board: boardIdentifier(value.board, 'Factory transition board'),\n stage: boardIdentifier(value.stage, 'Factory transition stage'),\n ...(message ? { message } : {}),\n ...(value.reenter === true ? { reenter: true } : {}),\n };\n }\n case 'upsertLinkedWorkItem': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'board',\n 'source',\n 'sourceKey',\n // Decisions saved before claims were dropped still carry it; it is ignored.\n 'claimKey',\n 'title',\n 'url',\n 'stage',\n 'skipRules',\n 'metadata',\n ],\n 'Factory linked work item decision',\n );\n if (value.skipRules !== undefined && typeof value.skipRules !== 'boolean') {\n throw new FactoryRuleValidationError('Factory linked work item skipRules must be a boolean.');\n }\n const url = value.url;\n if (url !== null && (typeof url !== 'string' || url.length > MAX_URL_LENGTH || !/^https?:\\/\\//.test(url))) {\n throw new FactoryRuleValidationError('Factory linked work item URL is invalid.');\n }\n const metadata = sanitizeMetadata(value.metadata);\n return {\n type,\n ...commonCommitFields(value),\n board: boardIdentifier(value.board, 'Factory linked work item board'),\n source: enumValue(value.source, WORK_ITEM_SOURCES, 'Factory linked work item source'),\n sourceKey: boundedString(value.sourceKey, 'Factory linked work item sourceKey', MAX_SOURCE_KEY_LENGTH),\n title: boundedString(value.title, 'Factory linked work item title', MAX_TITLE_LENGTH),\n url,\n stage: boardIdentifier(value.stage, 'Factory linked work item stage'),\n ...(value.skipRules === true ? { skipRules: true } : {}),\n ...(metadata ? { metadata } : {}),\n };\n }\n case 'invokeSkill': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'role',\n 'skillName',\n 'prompt',\n 'arguments',\n 'precedingMessage',\n 'cancelInFlight',\n 'startsAfterOwnMove',\n 'resume',\n ],\n 'Factory invoke skill decision',\n );\n // A run activates a skill or carries a prompt, never both: they are two\n // ways to author the same kickoff message, so accepting both would leave\n // the dispatcher picking a winner.\n if ((value.skillName === undefined) === (value.prompt === undefined)) {\n throw new FactoryRuleValidationError('Factory skill invocation needs exactly one of skillName or prompt.');\n }\n const args = optionalBoundedString(value.arguments, 'Factory skill arguments', MAX_ARGUMENTS_LENGTH);\n const precedingMessage = optionalBoundedString(\n value.precedingMessage,\n 'Factory skill preceding message',\n MAX_MESSAGE_LENGTH,\n );\n if (value.cancelInFlight !== undefined && typeof value.cancelInFlight !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill cancelInFlight must be a boolean.');\n }\n if (value.startsAfterOwnMove !== undefined && typeof value.startsAfterOwnMove !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill startsAfterOwnMove must be a boolean.');\n }\n if (value.resume !== undefined && typeof value.resume !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill resume must be a boolean.');\n }\n // Resume continues an already-active skill by name; a plain prompt run has no\n // skill to resume, so the dispatcher would silently ignore the flag.\n if (value.resume === true && value.skillName === undefined) {\n throw new FactoryRuleValidationError('Factory skill resume requires skillName.');\n }\n return {\n type,\n ...commonCommitFields(value),\n role: boundedString(value.role, 'Factory skill role', MAX_ROLE_LENGTH, IDENTIFIER_RE),\n ...(value.skillName === undefined\n ? { prompt: boundedString(value.prompt, 'Factory skill prompt', MAX_MESSAGE_LENGTH) }\n : {\n skillName: boundedString(value.skillName, 'Factory skill name', MAX_SKILL_NAME_LENGTH, SKILL_NAME_RE),\n ...(value.resume === true ? { resume: true } : {}),\n }),\n ...(args ? { arguments: args } : {}),\n ...(precedingMessage ? { precedingMessage } : {}),\n ...(value.cancelInFlight === true ? { cancelInFlight: true } : {}),\n ...(value.startsAfterOwnMove === true ? { startsAfterOwnMove: true } : {}),\n };\n }\n case 'sendMessage': {\n assertExactKeys(\n value,\n ['type', 'idempotencyKey', 'role', 'message', 'priority', 'idleBehavior', 'prepareBinding'],\n 'Factory send message decision',\n );\n const priority =\n value.priority === undefined\n ? undefined\n : enumValue(value.priority, ['medium', 'high', 'urgent'] as const, 'Factory message priority');\n const idleBehavior =\n value.idleBehavior === undefined\n ? undefined\n : enumValue(value.idleBehavior, ['persist', 'wake'] as const, 'Factory message idle behavior');\n if (value.prepareBinding !== undefined && typeof value.prepareBinding !== 'boolean') {\n throw new FactoryRuleValidationError('Factory message prepareBinding must be a boolean.');\n }\n if (value.prepareBinding === true && value.role === undefined) {\n throw new FactoryRuleValidationError('Factory message prepareBinding requires a role.');\n }\n const role =\n value.role === undefined\n ? undefined\n : boundedString(value.role, 'Factory message role', MAX_ROLE_LENGTH, IDENTIFIER_RE);\n return {\n type,\n ...commonCommitFields(value),\n ...(role ? { role } : {}),\n message: boundedString(value.message, 'Factory message', MAX_MESSAGE_LENGTH),\n ...(priority ? { priority } : {}),\n ...(idleBehavior ? { idleBehavior } : {}),\n ...(value.prepareBinding === true ? { prepareBinding: true } : {}),\n };\n }\n case 'notify': {\n assertExactKeys(value, ['type', 'idempotencyKey', 'title', 'body', 'level'], 'Factory notify decision');\n const body = optionalBoundedString(value.body, 'Factory notification body', MAX_MESSAGE_LENGTH);\n const level =\n value.level === undefined\n ? undefined\n : enumValue(value.level, ['info', 'warning', 'error'] as const, 'Factory notification level');\n return {\n type,\n ...commonCommitFields(value),\n title: boundedString(value.title, 'Factory notification title', MAX_TITLE_LENGTH),\n ...(body ? { body } : {}),\n ...(level ? { level } : {}),\n };\n }\n case 'dismissStaleReviews': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'installationId',\n 'repository',\n 'pullRequestNumber',\n 'approvingReviewId',\n 'approvingAuthor',\n ],\n 'Factory dismiss stale reviews decision',\n );\n for (const key of ['installationId', 'pullRequestNumber'] as const) {\n if (!Number.isSafeInteger(value[key]) || (value[key] as number) <= 0) {\n throw new FactoryRuleValidationError(`Factory dismiss stale reviews ${key} must be a positive integer.`);\n }\n }\n return {\n type,\n ...commonCommitFields(value),\n installationId: value.installationId as number,\n repository: boundedString(value.repository, 'Factory dismiss stale reviews repository', MAX_TITLE_LENGTH),\n pullRequestNumber: value.pullRequestNumber as number,\n approvingReviewId: boundedString(value.approvingReviewId, 'Factory approving review id', MAX_TITLE_LENGTH),\n approvingAuthor: boundedString(value.approvingAuthor, 'Factory approving review author', MAX_TITLE_LENGTH),\n };\n }\n default:\n throw new FactoryRuleValidationError('Factory rule decision type is unsupported.');\n }\n}\n\nexport function validateFactoryRuleDecisions(values: readonly unknown[], causalDepth = 0): FactoryCommitDecision[] {\n if (values.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Factory rule produced too many decisions.');\n }\n const decisions: FactoryCommitDecision[] = [];\n for (const value of values) {\n const decision = validateFactoryRuleDecision(value, causalDepth);\n if (decision.type === 'reject') {\n throw new FactoryRuleValidationError('A rejection cannot be persisted with commit decisions.');\n }\n decisions.push(decision);\n }\n const keys = decisions.map(decision => decision.idempotencyKey);\n if (new Set(keys).size !== keys.length) {\n throw new FactoryRuleValidationError('Factory decisions require unique idempotency keys.');\n }\n return decisions;\n}\n"],"mappings":";AASA,MAAa,gCAAgC;AAE7C,MAAM,qBAAqB;AAC3B,MAAM,6BAA6B;AACnC,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAC3B,MAAM,uBAAuB;AAC7B,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB;AACpC,MAAa,wBAAwB;AACrC,MAAM,wBAAwB;AAC9B,MAAM,iBAAiB;AACvB,MAAM,2BAA2B;AACj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CACrF;AACF;AAEA,SAAgB,6BAA6B,QAA4B,cAAc,GAA4B;CACjH,IAAI,OAAO,SAAS,0BAClB,MAAM,IAAI,2BAA2B,2CAA2C;CAElF,MAAM,YAAqC,CAAC;CAC5C,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,4BAA4B,OAAO,WAAW;EAC/D,IAAI,SAAS,SAAS,UACpB,MAAM,IAAI,2BAA2B,wDAAwD;EAE/F,UAAU,KAAK,QAAQ;CACzB;CACA,MAAM,OAAO,UAAU,KAAI,aAAY,SAAS,cAAc;CAC9D,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,KAAK,QAC9B,MAAM,IAAI,2BAA2B,oDAAoD;CAE3F,OAAO;AACT"}
1
+ {"version":3,"file":"validation.js","names":[],"sources":["../../src/rules/validation.ts"],"sourcesContent":["import { ACTIVITY_EVENTS, CLOSE_REASONS, STATUS_EVENTS } from '../boards/board-events.js';\nimport type { BoardEventFacts } from '../boards/board-events.js';\nimport type { BoardRegistry } from '../boards/registry.js';\nimport type {\n FactoryCommitDecision,\n FactoryRuleDecision,\n FactoryRuleJsonValue,\n FactoryRuleRejectionCode,\n FactoryRouteEventDecision,\n FactoryTransitionDecision,\n WorkItemSource,\n} from './types.js';\n\nexport const MAX_FACTORY_RULE_CAUSAL_DEPTH = 8;\n\nconst MAX_VERSION_LENGTH = 128;\nconst MAX_IDEMPOTENCY_KEY_LENGTH = 256;\nconst MAX_REASON_LENGTH = 512;\nconst MAX_TITLE_LENGTH = 512;\nconst MAX_MESSAGE_LENGTH = 8_192;\nconst MAX_ARGUMENTS_LENGTH = 4_096;\nexport const MAX_ROLE_LENGTH = 32;\nexport const MAX_TOOL_NAME_LENGTH = 128;\nexport const MAX_SKILL_NAME_LENGTH = 128;\nconst MAX_SOURCE_KEY_LENGTH = 256;\nconst MAX_URL_LENGTH = 2_048;\nconst MAX_METADATA_JSON_LENGTH = 16_384;\nconst MAX_JSON_DEPTH = 8;\nconst MAX_JSON_COLLECTION_SIZE = 100;\n\nexport const MAX_BOARD_IDENTIFIER_LENGTH = 128;\n/** A source reference such as `acme/app#12` or `group/sub/project#3`. */\nconst SOURCE_REFERENCE_RE = /^[a-z0-9_][a-z0-9_.\\/-]*#\\d+$/i;\n/** A provider login such as `octocat`, `dependabot[bot]`, `jane.doe` or GitLab's `_jane`. */\nconst LOGIN_RE = /^[a-z0-9_][a-z0-9_.-]*(\\[bot\\])?$/i;\nconst MAX_LOGIN_LENGTH = 100;\nexport const IDENTIFIER_RE = /^[a-z0-9][a-z0-9_-]*$/i;\nexport const BOARD_IDENTIFIER_RE = IDENTIFIER_RE;\nexport const SKILL_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\nconst SENSITIVE_KEY_RE = /(?:authorization|cookie|credential|password|secret|token)/i;\nconst WORK_ITEM_SOURCES: readonly WorkItemSource[] = [\n 'github-issue',\n 'github-pr',\n 'gitlab-issue',\n 'gitlab-pr',\n 'linear-issue',\n 'jira-issue',\n 'incidentio-follow-up',\n 'manual',\n];\nconst REJECTION_CODES: readonly FactoryRuleRejectionCode[] = [\n 'forbidden',\n 'invalid_transition',\n 'missing_binding',\n 'stale',\n 'timeout',\n 'rule_error',\n 'causal_depth_exceeded',\n 'repeated_transition',\n];\n\nexport class FactoryRuleValidationError extends Error {\n readonly code = 'invalid_factory_rule';\n\n constructor(message: string) {\n super(message);\n this.name = 'FactoryRuleValidationError';\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction assertExactKeys(value: Record<string, unknown>, keys: readonly string[], label: string): void {\n const allowed = new Set(keys);\n if (Object.keys(value).some(key => !allowed.has(key))) {\n throw new FactoryRuleValidationError(`${label} contains an unsupported field.`);\n }\n}\n\nfunction boundedString(value: unknown, label: string, max: number, pattern?: RegExp): string {\n if (typeof value !== 'string') throw new FactoryRuleValidationError(`${label} must be a string.`);\n const normalized = value.trim();\n if (normalized.length === 0 || normalized.length > max || (pattern && !pattern.test(normalized))) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return normalized;\n}\n\nexport function isBoardIdentifier(value: unknown): value is string {\n return typeof value === 'string' && value.length <= MAX_BOARD_IDENTIFIER_LENGTH && BOARD_IDENTIFIER_RE.test(value);\n}\n\nfunction boardIdentifier(value: unknown, label: string): string {\n if (!isBoardIdentifier(value)) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return value;\n}\n\nfunction boardEvent(value: unknown, label: string): BoardEventFacts {\n if (!isPlainObject(value)) throw new FactoryRuleValidationError(`${label} event must be an object.`);\n assertExactKeys(value, ['type', 'reason'], `${label} event`);\n const type = enumValue(value.type, STATUS_EVENTS, `${label} event type`);\n const reason =\n value.reason === undefined ? undefined : enumValue(value.reason, CLOSE_REASONS, `${label} event reason`);\n return { type, ...(reason ? { reason } : {}) };\n}\n\nfunction linkedItemReference(value: unknown, field: 'attachTo' | 'closesIssue'): { workItemId: string } | undefined {\n if (value === undefined) return undefined;\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n throw new FactoryRuleValidationError(`Factory linked work item ${field} must be an object.`);\n }\n assertExactKeys(value as Record<string, unknown>, ['workItemId'], `Factory linked work item ${field}`);\n const { workItemId } = value as Record<string, unknown>;\n return { workItemId: boundedString(workItemId, `Factory linked work item ${field}.workItemId`, 128) };\n}\n\nexport function assertFactoryDecisionTarget(\n decision: FactoryRuleDecision,\n boards: BoardRegistry,\n itemBoard?: string | null,\n): void {\n if (decision.type !== 'transition' && decision.type !== 'upsertLinkedWorkItem') return;\n const board = boards.get(decision.board);\n if (!board) throw new FactoryRuleValidationError('Factory decision target board is not installed.');\n if (!Object.hasOwn(board.phases, decision.stage)) {\n throw new FactoryRuleValidationError('Factory decision target phase is not defined on its board.');\n }\n if (decision.type === 'transition' && itemBoard !== undefined && itemBoard !== decision.board) {\n throw new FactoryRuleValidationError('Factory transition cannot change the item board.');\n }\n}\n\nconst MAX_GOAL_OBJECTIVE_LENGTH = 2_000;\nconst MAX_GOAL_RUNS = 50;\n\nfunction invokeSkillGoal(value: unknown): { objective: string; maxRuns?: number } | undefined {\n if (value === undefined) return undefined;\n if (!isPlainObject(value)) throw new FactoryRuleValidationError('Factory skill goal must be an object.');\n assertExactKeys(value, ['objective', 'maxRuns'], 'Factory skill goal');\n const objective = boundedString(value.objective, 'Factory skill goal objective', MAX_GOAL_OBJECTIVE_LENGTH);\n const { maxRuns } = value;\n if (\n maxRuns !== undefined &&\n (typeof maxRuns !== 'number' || !Number.isInteger(maxRuns) || maxRuns < 1 || maxRuns > MAX_GOAL_RUNS)\n ) {\n throw new FactoryRuleValidationError('Factory skill goal maxRuns is invalid.');\n }\n return { objective, ...(maxRuns !== undefined ? { maxRuns } : {}) };\n}\n\nfunction optionalBoundedString(value: unknown, label: string, max: number): string | undefined {\n if (value === undefined) return undefined;\n return boundedString(value, label, max);\n}\n\nfunction enumValue<T extends string>(value: unknown, allowed: readonly T[], label: string): T {\n if (typeof value !== 'string' || !allowed.includes(value as T)) {\n throw new FactoryRuleValidationError(`${label} is invalid.`);\n }\n return value as T;\n}\n\nexport function normalizeFactoryRuleJsonValue(\n value: unknown,\n depth = 0,\n seen = new Set<object>(),\n): FactoryRuleJsonValue {\n if (value === null || typeof value === 'boolean' || typeof value === 'string') return value;\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) throw new FactoryRuleValidationError('Rule metadata must contain finite numbers.');\n return value;\n }\n if (depth >= MAX_JSON_DEPTH || (typeof value !== 'object' && !Array.isArray(value))) {\n throw new FactoryRuleValidationError('Rule metadata is not bounded JSON.');\n }\n if (seen.has(value as object)) throw new FactoryRuleValidationError('Rule metadata must not contain cycles.');\n seen.add(value as object);\n try {\n if (Array.isArray(value)) {\n if (value.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Rule metadata contains too many entries.');\n }\n return value.map(entry => normalizeFactoryRuleJsonValue(entry, depth + 1, seen));\n }\n if (!isPlainObject(value)) throw new FactoryRuleValidationError('Rule metadata must use plain objects.');\n const entries = Object.entries(value);\n if (entries.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Rule metadata contains too many fields.');\n }\n const sanitized: Record<string, FactoryRuleJsonValue> = {};\n for (const [key, entry] of entries) {\n const normalizedKey = boundedString(key, 'Rule metadata key', 128, IDENTIFIER_RE);\n sanitized[normalizedKey] = SENSITIVE_KEY_RE.test(normalizedKey)\n ? '[REDACTED]'\n : normalizeFactoryRuleJsonValue(entry, depth + 1, seen);\n }\n return sanitized;\n } finally {\n seen.delete(value as object);\n }\n}\n\nfunction sanitizeMetadata(value: unknown): Record<string, FactoryRuleJsonValue> | undefined {\n if (value === undefined) return undefined;\n const sanitized = normalizeFactoryRuleJsonValue(value);\n if (!isPlainObject(sanitized)) throw new FactoryRuleValidationError('Rule metadata must be an object.');\n if (JSON.stringify(sanitized).length > MAX_METADATA_JSON_LENGTH) {\n throw new FactoryRuleValidationError('Rule metadata is too large.');\n }\n return sanitized;\n}\n\nexport const DEFAULT_FACTORY_CONFIG_VERSION = 'factory-config-v1';\n\n/** Operator-maintained provenance label stamped on transition audit and deferred-decision rows. */\nexport function assertFactoryConfigVersion(value: unknown): string {\n return boundedString(value, 'Factory configVersion', MAX_VERSION_LENGTH);\n}\n\nfunction commonCommitFields(value: Record<string, unknown>): { idempotencyKey: string } {\n return {\n idempotencyKey: boundedString(value.idempotencyKey, 'Factory decision idempotencyKey', MAX_IDEMPOTENCY_KEY_LENGTH),\n };\n}\n\nexport function validateFactoryRuleDecision(value: unknown, causalDepth = 0): FactoryRuleDecision {\n if (causalDepth > MAX_FACTORY_RULE_CAUSAL_DEPTH) {\n throw new FactoryRuleValidationError('Factory rule causal depth exceeded.');\n }\n if (!isPlainObject(value)) throw new FactoryRuleValidationError('Factory rule decision must be an object.');\n const type = value.type;\n if (typeof type !== 'string') throw new FactoryRuleValidationError('Factory rule decision type is required.');\n\n switch (type) {\n case 'reject': {\n assertExactKeys(value, ['type', 'code', 'reason'], 'Factory reject decision');\n return {\n type,\n code: enumValue(value.code, REJECTION_CODES, 'Factory rejection code'),\n reason: boundedString(value.reason, 'Factory rejection reason', MAX_REASON_LENGTH),\n };\n }\n case 'transition': {\n assertExactKeys(\n value,\n ['type', 'idempotencyKey', 'board', 'stage', 'message', 'reenter', 'event'],\n 'Factory transition decision',\n );\n if (value.reenter !== undefined && typeof value.reenter !== 'boolean') {\n throw new FactoryRuleValidationError('Factory transition reenter must be a boolean.');\n }\n let message: { text: string; role?: string } | undefined;\n if (value.message !== undefined) {\n if (!isPlainObject(value.message)) {\n throw new FactoryRuleValidationError('Factory transition message must be an object.');\n }\n assertExactKeys(value.message, ['text', 'role'], 'Factory transition message');\n const role =\n value.message.role === undefined\n ? undefined\n : boundedString(value.message.role, 'Factory transition message role', MAX_ROLE_LENGTH, IDENTIFIER_RE);\n message = {\n text: boundedString(value.message.text, 'Factory transition message text', MAX_MESSAGE_LENGTH),\n ...(role ? { role } : {}),\n };\n }\n return {\n type,\n ...commonCommitFields(value),\n board: boardIdentifier(value.board, 'Factory transition board'),\n stage: boardIdentifier(value.stage, 'Factory transition stage'),\n ...(message ? { message } : {}),\n ...(value.reenter === true ? { reenter: true } : {}),\n ...(value.event !== undefined ? { event: boardEvent(value.event, 'Factory transition') } : {}),\n };\n }\n case 'routeEvent': {\n assertExactKeys(value, ['type', 'idempotencyKey', 'event'], 'Factory routeEvent decision');\n return { type, ...commonCommitFields(value), event: boardEvent(value.event, 'Factory routeEvent') };\n }\n case 'signalActivity': {\n assertExactKeys(\n value,\n ['type', 'idempotencyKey', 'event', 'reference', 'url', 'author', 'authorTrusted', 'idleBehavior'],\n 'Factory signalActivity decision',\n );\n const url = value.url;\n if (typeof url !== 'string' || url.length > MAX_URL_LENGTH || !/^https?:\\/\\/\\S+$/.test(url)) {\n throw new FactoryRuleValidationError('Factory signalActivity url must be an http(s) URL.');\n }\n if (typeof value.authorTrusted !== 'boolean') {\n throw new FactoryRuleValidationError('Factory signalActivity authorTrusted must be a boolean.');\n }\n const author =\n value.author === undefined\n ? undefined\n : boundedString(value.author, 'Factory signalActivity author', MAX_LOGIN_LENGTH, LOGIN_RE);\n return {\n type,\n ...commonCommitFields(value),\n event: enumValue(value.event, ACTIVITY_EVENTS, 'Factory signalActivity event'),\n reference: boundedString(\n value.reference,\n 'Factory signalActivity reference',\n MAX_SOURCE_KEY_LENGTH,\n SOURCE_REFERENCE_RE,\n ),\n url,\n ...(author ? { author } : {}),\n authorTrusted: value.authorTrusted,\n ...(value.idleBehavior === undefined\n ? {}\n : {\n idleBehavior: enumValue(\n value.idleBehavior,\n ['wake', 'persist'] as const,\n 'Factory signalActivity idleBehavior',\n ),\n }),\n };\n }\n case 'upsertLinkedWorkItem': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'board',\n 'source',\n 'sourceKey',\n // Decisions saved before claims were dropped still carry it; it is ignored.\n 'claimKey',\n 'title',\n 'url',\n 'stage',\n 'skipRules',\n 'attachTo',\n 'closesIssue',\n 'metadata',\n ],\n 'Factory linked work item decision',\n );\n if (value.skipRules !== undefined && typeof value.skipRules !== 'boolean') {\n throw new FactoryRuleValidationError('Factory linked work item skipRules must be a boolean.');\n }\n const url = value.url;\n if (url !== null && (typeof url !== 'string' || url.length > MAX_URL_LENGTH || !/^https?:\\/\\//.test(url))) {\n throw new FactoryRuleValidationError('Factory linked work item URL is invalid.');\n }\n const metadata = sanitizeMetadata(value.metadata);\n const attachTo = linkedItemReference(value.attachTo, 'attachTo');\n const closesIssue = linkedItemReference(value.closesIssue, 'closesIssue');\n return {\n type,\n ...commonCommitFields(value),\n board: boardIdentifier(value.board, 'Factory linked work item board'),\n source: enumValue(value.source, WORK_ITEM_SOURCES, 'Factory linked work item source'),\n sourceKey: boundedString(value.sourceKey, 'Factory linked work item sourceKey', MAX_SOURCE_KEY_LENGTH),\n title: boundedString(value.title, 'Factory linked work item title', MAX_TITLE_LENGTH),\n url,\n stage: boardIdentifier(value.stage, 'Factory linked work item stage'),\n ...(value.skipRules === true ? { skipRules: true } : {}),\n ...(attachTo ? { attachTo } : {}),\n ...(closesIssue ? { closesIssue } : {}),\n ...(metadata ? { metadata } : {}),\n };\n }\n case 'invokeSkill': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'role',\n 'skillName',\n 'prompt',\n 'arguments',\n 'precedingMessage',\n 'cancelInFlight',\n 'startsAfterOwnMove',\n 'resume',\n 'goal',\n ],\n 'Factory invoke skill decision',\n );\n // A run activates a skill or carries a prompt, never both: they are two\n // ways to author the same kickoff message, so accepting both would leave\n // the dispatcher picking a winner.\n if ((value.skillName === undefined) === (value.prompt === undefined)) {\n throw new FactoryRuleValidationError('Factory skill invocation needs exactly one of skillName or prompt.');\n }\n const args = optionalBoundedString(value.arguments, 'Factory skill arguments', MAX_ARGUMENTS_LENGTH);\n const precedingMessage = optionalBoundedString(\n value.precedingMessage,\n 'Factory skill preceding message',\n MAX_MESSAGE_LENGTH,\n );\n if (value.cancelInFlight !== undefined && typeof value.cancelInFlight !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill cancelInFlight must be a boolean.');\n }\n if (value.startsAfterOwnMove !== undefined && typeof value.startsAfterOwnMove !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill startsAfterOwnMove must be a boolean.');\n }\n if (value.resume !== undefined && typeof value.resume !== 'boolean') {\n throw new FactoryRuleValidationError('Factory skill resume must be a boolean.');\n }\n // Resume continues an already-active skill by name; a plain prompt run has no\n // skill to resume, so the dispatcher would silently ignore the flag.\n if (value.resume === true && value.skillName === undefined) {\n throw new FactoryRuleValidationError('Factory skill resume requires skillName.');\n }\n const goal = invokeSkillGoal(value.goal);\n return {\n type,\n ...commonCommitFields(value),\n role: boundedString(value.role, 'Factory skill role', MAX_ROLE_LENGTH, IDENTIFIER_RE),\n ...(value.skillName === undefined\n ? { prompt: boundedString(value.prompt, 'Factory skill prompt', MAX_MESSAGE_LENGTH) }\n : {\n skillName: boundedString(value.skillName, 'Factory skill name', MAX_SKILL_NAME_LENGTH, SKILL_NAME_RE),\n ...(value.resume === true ? { resume: true } : {}),\n }),\n ...(args ? { arguments: args } : {}),\n ...(precedingMessage ? { precedingMessage } : {}),\n ...(value.cancelInFlight === true ? { cancelInFlight: true } : {}),\n ...(value.startsAfterOwnMove === true ? { startsAfterOwnMove: true } : {}),\n ...(goal ? { goal } : {}),\n };\n }\n case 'sendMessage': {\n assertExactKeys(\n value,\n ['type', 'idempotencyKey', 'role', 'message', 'priority', 'idleBehavior', 'prepareBinding'],\n 'Factory send message decision',\n );\n const priority =\n value.priority === undefined\n ? undefined\n : enumValue(value.priority, ['medium', 'high', 'urgent'] as const, 'Factory message priority');\n const idleBehavior =\n value.idleBehavior === undefined\n ? undefined\n : enumValue(value.idleBehavior, ['persist', 'wake'] as const, 'Factory message idle behavior');\n if (value.prepareBinding !== undefined && typeof value.prepareBinding !== 'boolean') {\n throw new FactoryRuleValidationError('Factory message prepareBinding must be a boolean.');\n }\n if (value.prepareBinding === true && value.role === undefined) {\n throw new FactoryRuleValidationError('Factory message prepareBinding requires a role.');\n }\n const role =\n value.role === undefined\n ? undefined\n : boundedString(value.role, 'Factory message role', MAX_ROLE_LENGTH, IDENTIFIER_RE);\n return {\n type,\n ...commonCommitFields(value),\n ...(role ? { role } : {}),\n message: boundedString(value.message, 'Factory message', MAX_MESSAGE_LENGTH),\n ...(priority ? { priority } : {}),\n ...(idleBehavior ? { idleBehavior } : {}),\n ...(value.prepareBinding === true ? { prepareBinding: true } : {}),\n };\n }\n case 'notify': {\n assertExactKeys(value, ['type', 'idempotencyKey', 'title', 'body', 'level'], 'Factory notify decision');\n const body = optionalBoundedString(value.body, 'Factory notification body', MAX_MESSAGE_LENGTH);\n const level =\n value.level === undefined\n ? undefined\n : enumValue(value.level, ['info', 'warning', 'error'] as const, 'Factory notification level');\n return {\n type,\n ...commonCommitFields(value),\n title: boundedString(value.title, 'Factory notification title', MAX_TITLE_LENGTH),\n ...(body ? { body } : {}),\n ...(level ? { level } : {}),\n };\n }\n case 'dismissStaleReviews': {\n assertExactKeys(\n value,\n [\n 'type',\n 'idempotencyKey',\n 'installationId',\n 'repository',\n 'pullRequestNumber',\n 'approvingReviewId',\n 'approvingAuthor',\n ],\n 'Factory dismiss stale reviews decision',\n );\n for (const key of ['installationId', 'pullRequestNumber'] as const) {\n if (!Number.isSafeInteger(value[key]) || (value[key] as number) <= 0) {\n throw new FactoryRuleValidationError(`Factory dismiss stale reviews ${key} must be a positive integer.`);\n }\n }\n return {\n type,\n ...commonCommitFields(value),\n installationId: value.installationId as number,\n repository: boundedString(value.repository, 'Factory dismiss stale reviews repository', MAX_TITLE_LENGTH),\n pullRequestNumber: value.pullRequestNumber as number,\n approvingReviewId: boundedString(value.approvingReviewId, 'Factory approving review id', MAX_TITLE_LENGTH),\n approvingAuthor: boundedString(value.approvingAuthor, 'Factory approving review author', MAX_TITLE_LENGTH),\n };\n }\n default:\n throw new FactoryRuleValidationError('Factory rule decision type is unsupported.');\n }\n}\n\nexport function validateFactoryRuleDecisions(values: readonly unknown[], causalDepth = 0): FactoryCommitDecision[] {\n if (values.length > MAX_JSON_COLLECTION_SIZE) {\n throw new FactoryRuleValidationError('Factory rule produced too many decisions.');\n }\n const decisions: FactoryCommitDecision[] = [];\n for (const value of values) {\n const decision = validateFactoryRuleDecision(value, causalDepth);\n if (decision.type === 'reject') {\n throw new FactoryRuleValidationError('A rejection cannot be persisted with commit decisions.');\n }\n decisions.push(decision);\n }\n const keys = decisions.map(decision => decision.idempotencyKey);\n if (new Set(keys).size !== keys.length) {\n throw new FactoryRuleValidationError('Factory decisions require unique idempotency keys.');\n }\n return decisions;\n}\n"],"mappings":";;AAaA,MAAa,gCAAgC;AAE7C,MAAM,qBAAqB;AAC3B,MAAM,6BAA6B;AACnC,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,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iC,IAAI,6BAA6B;GAG3G,OAAO;IACL;IACA,GAAG,mBAAmB,KAAK;IAC3B,gBAAgB,MAAM;IACtB,YAAY,cAAc,MAAM,YAAY,4CAA4C,gBAAgB;IACxG,mBAAmB,MAAM;IACzB,mBAAmB,cAAc,MAAM,mBAAmB,+BAA+B,gBAAgB;IACzG,iBAAiB,cAAc,MAAM,iBAAiB,mCAAmC,gBAAgB;GAC3G;EAEF,SACE,MAAM,IAAI,2BAA2B,4CAA4C;CACrF;AACF;AAEA,SAAgB,6BAA6B,QAA4B,cAAc,GAA4B;CACjH,IAAI,OAAO,SAAS,0BAClB,MAAM,IAAI,2BAA2B,2CAA2C;CAElF,MAAM,YAAqC,CAAC;CAC5C,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,4BAA4B,OAAO,WAAW;EAC/D,IAAI,SAAS,SAAS,UACpB,MAAM,IAAI,2BAA2B,wDAAwD;EAE/F,UAAU,KAAK,QAAQ;CACzB;CACA,MAAM,OAAO,UAAU,KAAI,aAAY,SAAS,cAAc;CAC9D,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,SAAS,KAAK,QAC9B,MAAM,IAAI,2BAA2B,oDAAoD;CAE3F,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- export type RunErrorRecovery = 'continue' | 'credentials' | 'model' | 'new_session';
1
+ export type RunErrorRecovery = 'continue' | 'credentials' | 'credits' | 'model' | 'new_session';
2
2
  export interface RunErrorDescription {
3
3
  title: string;
4
4
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"run-error.d.ts","sourceRoot":"","sources":["../src/run-error.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,CAAC;AAEpF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAE7E"}
1
+ {"version":3,"file":"run-error.d.ts","sourceRoot":"","sources":["../src/run-error.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;AAEhG,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAE7E"}
package/dist/run-error.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { MASTRA_GATEWAY_PREFIX } from "@mastra/code-sdk/providers/model-ids";
1
2
  import { PROVIDER_CALL_ERROR_NAME, classifyProviderError, providerErrorReason, providerModelId } from "@mastra/core/error";
2
3
  import { PROVIDER_AUTH_REQUIRED_ERROR } from "@mastra/code-sdk/auth/provider-auth-error";
3
4
  // src/run-error.ts
@@ -16,11 +17,21 @@ function explainRunError(error) {
16
17
  recoveries: ["credentials", "model"]
17
18
  };
18
19
  switch (classifyProviderError(error)) {
19
- case "quota": return {
20
- title: "Provider quota exhausted",
21
- message: afterProviderReason(error, "Check the provider account’s billing or usage allowance, or use another credential or model."),
22
- recoveries: ["credentials", "model"]
23
- };
20
+ case "quota":
21
+ if (isMastraGatewayError(error)) return {
22
+ title: "Out of Mastra Gateway credits",
23
+ message: "Your organization has no gateway credits left. Add credits, then continue the run, or choose another model.",
24
+ recoveries: [
25
+ "credits",
26
+ "continue",
27
+ "model"
28
+ ]
29
+ };
30
+ return {
31
+ title: "Provider quota exhausted",
32
+ message: afterProviderReason(error, "Check the provider account’s billing or usage allowance, or use another credential or model."),
33
+ recoveries: ["credentials", "model"]
34
+ };
24
35
  case "auth": return {
25
36
  title: "Provider access failed",
26
37
  message: afterProviderReason(error, "Review the credentials and model access configured for this session."),
@@ -68,6 +79,28 @@ function explainRunError(error) {
68
79
  case "unknown": return describeUnclassifiedError(error);
69
80
  }
70
81
  }
82
+ const MASTRA_GATEWAY_HOST = /(?:^|\.)gateway(?:-api)?\.mastra\.ai$/;
83
+ /**
84
+ * The Mastra Gateway answered: a `mastra/…` model, a request sent to its host, or its billing reply
85
+ * (which links to `gateway.mastra.ai`). The request reaches the gateway without the `mastra/` prefix.
86
+ */
87
+ function isMastraGatewayError(error) {
88
+ return providerModelId(error)?.startsWith(MASTRA_GATEWAY_PREFIX) === true || calledMastraGateway(error) || /gateway\.mastra\.ai/.test(providerErrorReason(error) ?? error.message);
89
+ }
90
+ /** Whether the request, or a provider error it wraps, went to the gateway's host. */
91
+ function calledMastraGateway(error, depth = 0) {
92
+ if (depth > 4 || typeof error !== "object" || error === null) return false;
93
+ const url = "url" in error ? error.url : void 0;
94
+ const cause = "cause" in error ? error.cause : void 0;
95
+ return typeof url === "string" && MASTRA_GATEWAY_HOST.test(hostOf(url)) || calledMastraGateway(cause, depth + 1);
96
+ }
97
+ function hostOf(url) {
98
+ try {
99
+ return new URL(url).hostname;
100
+ } catch {
101
+ return "";
102
+ }
103
+ }
71
104
  function afterProviderReason(error, next, fallback) {
72
105
  const reason = providerErrorReason(error) ?? fallback;
73
106
  return reason ? `${reason.replace(/\.?$/, ".")} ${next}` : next;
@@ -1 +1 @@
1
- {"version":3,"file":"run-error.js","names":[],"sources":["../src/run-error.ts"],"sourcesContent":["import { PROVIDER_AUTH_REQUIRED_ERROR } from '@mastra/code-sdk/auth/provider-auth-error';\nimport {\n classifyProviderError,\n PROVIDER_CALL_ERROR_NAME,\n providerErrorReason,\n providerModelId,\n} from '@mastra/core/error';\n\nexport type RunErrorRecovery = 'continue' | 'credentials' | 'model' | 'new_session';\n\nexport interface RunErrorDescription {\n title: string;\n message: string;\n recoveries: RunErrorRecovery[];\n model?: string;\n}\n\nexport interface RunErrorIdentity {\n name: string;\n message: string;\n}\n\nconst UNEXPECTED_ERROR = 'An unexpected error stopped the run. Copy the error details to investigate.';\nconst NO_REASON_AVAILABLE =\n 'The provider rejected the request. A specific reason isn’t available here. Copy the error details and check the server logs.';\n\nexport function describeRunError(error: RunErrorIdentity): RunErrorDescription {\n return { ...explainRunError(error), model: providerModelId(error) };\n}\n\nfunction explainRunError(error: RunErrorIdentity): Omit<RunErrorDescription, 'model'> {\n if (error.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { title: 'Provider sign-in required', message: error.message, recoveries: ['credentials', 'model'] };\n }\n switch (classifyProviderError(error)) {\n case 'quota':\n return {\n title: 'Provider quota exhausted',\n message: afterProviderReason(\n error,\n 'Check the provider account’s billing or usage allowance, or use another credential or model.',\n ),\n recoveries: ['credentials', 'model'],\n };\n case 'auth':\n return {\n title: 'Provider access failed',\n message: afterProviderReason(error, 'Review the credentials and model access configured for this session.'),\n recoveries: ['credentials', 'model'],\n };\n case 'context_overflow':\n return {\n title: 'Conversation exceeds the model’s limit',\n message: 'Choose a model with a larger context window or start a new session with a shorter prompt.',\n recoveries: ['model', 'new_session'],\n };\n case 'model_rejected':\n return {\n title: 'Model not available',\n message: afterProviderReason(\n error,\n 'Choose another model for this session.',\n 'The provider rejected this model.',\n ),\n recoveries: ['model'],\n };\n case 'tool_history_rejected':\n return {\n title: 'Conversation history rejected',\n message:\n 'The provider could not match a tool call with its result. Start a new session to keep working, and copy the error details so this session can be investigated.',\n recoveries: ['new_session'],\n };\n case 'invalid_request':\n return {\n title: 'Model request rejected',\n message: providerErrorReason(error) ?? NO_REASON_AVAILABLE,\n recoveries: ['model'],\n };\n case 'timeout':\n return {\n title: 'Request timed out',\n message: 'The request took too long to complete. Send a message to continue the run.',\n recoveries: ['continue'],\n };\n case 'rate_limited':\n return {\n title: 'Provider rate limit reached',\n message:\n 'The provider account behind this session’s credential hit a rate or usage limit. Continue once it resets, or use another credential or model.',\n recoveries: ['continue', 'credentials', 'model'],\n };\n case 'unavailable':\n return {\n title: 'Model provider temporarily unavailable',\n message:\n 'The provider could not complete the request. Send a message to continue the run, or choose another model.',\n recoveries: ['continue', 'model'],\n };\n case 'unknown':\n return describeUnclassifiedError(error);\n }\n}\n\nfunction afterProviderReason(error: RunErrorIdentity, next: string, fallback?: string): string {\n const reason = providerErrorReason(error) ?? fallback;\n return reason ? `${reason.replace(/\\.?$/, '.')} ${next}` : next;\n}\n\nfunction describeUnclassifiedError(error: RunErrorIdentity): Omit<RunErrorDescription, 'model'> {\n const message = providerErrorReason(error) ?? (error.message || UNEXPECTED_ERROR);\n const providerCall = PROVIDER_CALL_ERROR_NAME.test(error.name);\n return {\n title: providerCall ? 'Model request failed' : 'Run stopped',\n message,\n recoveries: providerCall ? ['model'] : [],\n };\n}\n"],"mappings":";;;AAsBA,MAAM,mBAAmB;AACzB,MAAM,sBACJ;AAEF,SAAgB,iBAAiB,OAA8C;CAC7E,OAAO;EAAE,GAAG,gBAAgB,KAAK;EAAG,OAAO,gBAAgB,KAAK;CAAE;AACpE;AAEA,SAAS,gBAAgB,OAA6D;CACpF,IAAI,MAAM,SAAS,8BACjB,OAAO;EAAE,OAAO;EAA6B,SAAS,MAAM;EAAS,YAAY,CAAC,eAAe,OAAO;CAAE;CAE5G,QAAQ,sBAAsB,KAAK,GAAnC;EACE,KAAK,SACH,OAAO;GACL,OAAO;GACP,SAAS,oBACP,OACA,8FACF;GACA,YAAY,CAAC,eAAe,OAAO;EACrC;EACF,KAAK,QACH,OAAO;GACL,OAAO;GACP,SAAS,oBAAoB,OAAO,sEAAsE;GAC1G,YAAY,CAAC,eAAe,OAAO;EACrC;EACF,KAAK,oBACH,OAAO;GACL,OAAO;GACP,SAAS;GACT,YAAY,CAAC,SAAS,aAAa;EACrC;EACF,KAAK,kBACH,OAAO;GACL,OAAO;GACP,SAAS,oBACP,OACA,0CACA,mCACF;GACA,YAAY,CAAC,OAAO;EACtB;EACF,KAAK,yBACH,OAAO;GACL,OAAO;GACP,SACE;GACF,YAAY,CAAC,aAAa;EAC5B;EACF,KAAK,mBACH,OAAO;GACL,OAAO;GACP,SAAS,oBAAoB,KAAK,KAAK;GACvC,YAAY,CAAC,OAAO;EACtB;EACF,KAAK,WACH,OAAO;GACL,OAAO;GACP,SAAS;GACT,YAAY,CAAC,UAAU;EACzB;EACF,KAAK,gBACH,OAAO;GACL,OAAO;GACP,SACE;GACF,YAAY;IAAC;IAAY;IAAe;GAAO;EACjD;EACF,KAAK,eACH,OAAO;GACL,OAAO;GACP,SACE;GACF,YAAY,CAAC,YAAY,OAAO;EAClC;EACF,KAAK,WACH,OAAO,0BAA0B,KAAK;CAC1C;AACF;AAEA,SAAS,oBAAoB,OAAyB,MAAc,UAA2B;CAC7F,MAAM,SAAS,oBAAoB,KAAK,KAAK;CAC7C,OAAO,SAAS,GAAG,OAAO,QAAQ,QAAQ,GAAG,EAAE,GAAG,SAAS;AAC7D;AAEA,SAAS,0BAA0B,OAA6D;CAC9F,MAAM,UAAU,oBAAoB,KAAK,MAAM,MAAM,WAAW;CAChE,MAAM,eAAe,yBAAyB,KAAK,MAAM,IAAI;CAC7D,OAAO;EACL,OAAO,eAAe,yBAAyB;EAC/C;EACA,YAAY,eAAe,CAAC,OAAO,IAAI,CAAC;CAC1C;AACF"}
1
+ {"version":3,"file":"run-error.js","names":[],"sources":["../src/run-error.ts"],"sourcesContent":["import { PROVIDER_AUTH_REQUIRED_ERROR } from '@mastra/code-sdk/auth/provider-auth-error';\nimport { MASTRA_GATEWAY_PREFIX } from '@mastra/code-sdk/providers/model-ids';\nimport {\n classifyProviderError,\n PROVIDER_CALL_ERROR_NAME,\n providerErrorReason,\n providerModelId,\n} from '@mastra/core/error';\n\nexport type RunErrorRecovery = 'continue' | 'credentials' | 'credits' | 'model' | 'new_session';\n\nexport interface RunErrorDescription {\n title: string;\n message: string;\n recoveries: RunErrorRecovery[];\n model?: string;\n}\n\nexport interface RunErrorIdentity {\n name: string;\n message: string;\n}\n\nconst UNEXPECTED_ERROR = 'An unexpected error stopped the run. Copy the error details to investigate.';\nconst NO_REASON_AVAILABLE =\n 'The provider rejected the request. A specific reason isn’t available here. Copy the error details and check the server logs.';\n\nexport function describeRunError(error: RunErrorIdentity): RunErrorDescription {\n return { ...explainRunError(error), model: providerModelId(error) };\n}\n\nfunction explainRunError(error: RunErrorIdentity): Omit<RunErrorDescription, 'model'> {\n if (error.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { title: 'Provider sign-in required', message: error.message, recoveries: ['credentials', 'model'] };\n }\n switch (classifyProviderError(error)) {\n case 'quota':\n if (isMastraGatewayError(error)) {\n return {\n title: 'Out of Mastra Gateway credits',\n message:\n 'Your organization has no gateway credits left. Add credits, then continue the run, or choose another model.',\n recoveries: ['credits', 'continue', 'model'],\n };\n }\n return {\n title: 'Provider quota exhausted',\n message: afterProviderReason(\n error,\n 'Check the provider account’s billing or usage allowance, or use another credential or model.',\n ),\n recoveries: ['credentials', 'model'],\n };\n case 'auth':\n return {\n title: 'Provider access failed',\n message: afterProviderReason(error, 'Review the credentials and model access configured for this session.'),\n recoveries: ['credentials', 'model'],\n };\n case 'context_overflow':\n return {\n title: 'Conversation exceeds the model’s limit',\n message: 'Choose a model with a larger context window or start a new session with a shorter prompt.',\n recoveries: ['model', 'new_session'],\n };\n case 'model_rejected':\n return {\n title: 'Model not available',\n message: afterProviderReason(\n error,\n 'Choose another model for this session.',\n 'The provider rejected this model.',\n ),\n recoveries: ['model'],\n };\n case 'tool_history_rejected':\n return {\n title: 'Conversation history rejected',\n message:\n 'The provider could not match a tool call with its result. Start a new session to keep working, and copy the error details so this session can be investigated.',\n recoveries: ['new_session'],\n };\n case 'invalid_request':\n return {\n title: 'Model request rejected',\n message: providerErrorReason(error) ?? NO_REASON_AVAILABLE,\n recoveries: ['model'],\n };\n case 'timeout':\n return {\n title: 'Request timed out',\n message: 'The request took too long to complete. Send a message to continue the run.',\n recoveries: ['continue'],\n };\n case 'rate_limited':\n return {\n title: 'Provider rate limit reached',\n message:\n 'The provider account behind this session’s credential hit a rate or usage limit. Continue once it resets, or use another credential or model.',\n recoveries: ['continue', 'credentials', 'model'],\n };\n case 'unavailable':\n return {\n title: 'Model provider temporarily unavailable',\n message:\n 'The provider could not complete the request. Send a message to continue the run, or choose another model.',\n recoveries: ['continue', 'model'],\n };\n case 'unknown':\n return describeUnclassifiedError(error);\n }\n}\n\nconst MASTRA_GATEWAY_HOST = /(?:^|\\.)gateway(?:-api)?\\.mastra\\.ai$/;\n\n/**\n * The Mastra Gateway answered: a `mastra/…` model, a request sent to its host, or its billing reply\n * (which links to `gateway.mastra.ai`). The request reaches the gateway without the `mastra/` prefix.\n */\nfunction isMastraGatewayError(error: RunErrorIdentity): boolean {\n return (\n providerModelId(error)?.startsWith(MASTRA_GATEWAY_PREFIX) === true ||\n calledMastraGateway(error) ||\n /gateway\\.mastra\\.ai/.test(providerErrorReason(error) ?? error.message)\n );\n}\n\n/** Whether the request, or a provider error it wraps, went to the gateway's host. */\nfunction calledMastraGateway(error: unknown, depth = 0): boolean {\n if (depth > 4 || typeof error !== 'object' || error === null) return false;\n const url = 'url' in error ? error.url : undefined;\n const cause = 'cause' in error ? error.cause : undefined;\n return (typeof url === 'string' && MASTRA_GATEWAY_HOST.test(hostOf(url))) || calledMastraGateway(cause, depth + 1);\n}\n\nfunction hostOf(url: string): string {\n try {\n return new URL(url).hostname;\n } catch {\n return '';\n }\n}\n\nfunction afterProviderReason(error: RunErrorIdentity, next: string, fallback?: string): string {\n const reason = providerErrorReason(error) ?? fallback;\n return reason ? `${reason.replace(/\\.?$/, '.')} ${next}` : next;\n}\n\nfunction describeUnclassifiedError(error: RunErrorIdentity): Omit<RunErrorDescription, 'model'> {\n const message = providerErrorReason(error) ?? (error.message || UNEXPECTED_ERROR);\n const providerCall = PROVIDER_CALL_ERROR_NAME.test(error.name);\n return {\n title: providerCall ? 'Model request failed' : 'Run stopped',\n message,\n recoveries: providerCall ? ['model'] : [],\n };\n}\n"],"mappings":";;;;AAuBA,MAAM,mBAAmB;AACzB,MAAM,sBACJ;AAEF,SAAgB,iBAAiB,OAA8C;CAC7E,OAAO;EAAE,GAAG,gBAAgB,KAAK;EAAG,OAAO,gBAAgB,KAAK;CAAE;AACpE;AAEA,SAAS,gBAAgB,OAA6D;CACpF,IAAI,MAAM,SAAS,8BACjB,OAAO;EAAE,OAAO;EAA6B,SAAS,MAAM;EAAS,YAAY,CAAC,eAAe,OAAO;CAAE;CAE5G,QAAQ,sBAAsB,KAAK,GAAnC;EACE,KAAK;GACH,IAAI,qBAAqB,KAAK,GAC5B,OAAO;IACL,OAAO;IACP,SACE;IACF,YAAY;KAAC;KAAW;KAAY;IAAO;GAC7C;GAEF,OAAO;IACL,OAAO;IACP,SAAS,oBACP,OACA,8FACF;IACA,YAAY,CAAC,eAAe,OAAO;GACrC;EACF,KAAK,QACH,OAAO;GACL,OAAO;GACP,SAAS,oBAAoB,OAAO,sEAAsE;GAC1G,YAAY,CAAC,eAAe,OAAO;EACrC;EACF,KAAK,oBACH,OAAO;GACL,OAAO;GACP,SAAS;GACT,YAAY,CAAC,SAAS,aAAa;EACrC;EACF,KAAK,kBACH,OAAO;GACL,OAAO;GACP,SAAS,oBACP,OACA,0CACA,mCACF;GACA,YAAY,CAAC,OAAO;EACtB;EACF,KAAK,yBACH,OAAO;GACL,OAAO;GACP,SACE;GACF,YAAY,CAAC,aAAa;EAC5B;EACF,KAAK,mBACH,OAAO;GACL,OAAO;GACP,SAAS,oBAAoB,KAAK,KAAK;GACvC,YAAY,CAAC,OAAO;EACtB;EACF,KAAK,WACH,OAAO;GACL,OAAO;GACP,SAAS;GAC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