@mastra/factory 0.24.0-alpha.0 → 0.24.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 (406) hide show
  1. package/README.md +106 -4
  2. package/dist/auth.d.ts +14 -0
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +45 -9
  5. package/dist/auth.js.map +1 -1
  6. package/dist/boards/review.d.ts.map +1 -1
  7. package/dist/boards/review.js +21 -1
  8. package/dist/boards/review.js.map +1 -1
  9. package/dist/boards/work-transition-policy.d.ts.map +1 -1
  10. package/dist/boards/work-transition-policy.js +12 -1
  11. package/dist/boards/work-transition-policy.js.map +1 -1
  12. package/dist/boards/work.d.ts +14 -0
  13. package/dist/boards/work.d.ts.map +1 -1
  14. package/dist/boards/work.js +70 -7
  15. package/dist/boards/work.js.map +1 -1
  16. package/dist/capabilities/version-control.d.ts +26 -0
  17. package/dist/capabilities/version-control.d.ts.map +1 -1
  18. package/dist/factory.d.ts +8 -0
  19. package/dist/factory.d.ts.map +1 -1
  20. package/dist/factory.js +354 -27
  21. package/dist/factory.js.map +1 -1
  22. package/dist/integrations/base.d.ts +1 -1
  23. package/dist/integrations/base.d.ts.map +1 -1
  24. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  25. package/dist/integrations/github/default-rules.js +1 -16
  26. package/dist/integrations/github/default-rules.js.map +1 -1
  27. package/dist/integrations/github/integration.d.ts.map +1 -1
  28. package/dist/integrations/github/integration.js +37 -1
  29. package/dist/integrations/github/integration.js.map +1 -1
  30. package/dist/integrations/github/routes.d.ts +1 -1
  31. package/dist/integrations/github/routes.d.ts.map +1 -1
  32. package/dist/integrations/github/routes.js +19 -11
  33. package/dist/integrations/github/routes.js.map +1 -1
  34. package/dist/integrations/github/rules.d.ts.map +1 -1
  35. package/dist/integrations/github/rules.js +26 -22
  36. package/dist/integrations/github/rules.js.map +1 -1
  37. package/dist/integrations/github/sandbox-release.d.ts +15 -3
  38. package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
  39. package/dist/integrations/github/sandbox-release.js +20 -3
  40. package/dist/integrations/github/sandbox-release.js.map +1 -1
  41. package/dist/integrations/github/sandbox.d.ts +2 -3
  42. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  43. package/dist/integrations/github/sandbox.js +78 -7
  44. package/dist/integrations/github/sandbox.js.map +1 -1
  45. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  46. package/dist/integrations/github/session-subscriptions.js +1 -2
  47. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  48. package/dist/integrations/github/subscriptions.d.ts +7 -4
  49. package/dist/integrations/github/subscriptions.d.ts.map +1 -1
  50. package/dist/integrations/github/subscriptions.js +5 -5
  51. package/dist/integrations/github/subscriptions.js.map +1 -1
  52. package/dist/integrations/github/webhook.d.ts +4 -2
  53. package/dist/integrations/github/webhook.d.ts.map +1 -1
  54. package/dist/integrations/github/webhook.js +59 -36
  55. package/dist/integrations/github/webhook.js.map +1 -1
  56. package/dist/integrations/gitlab/api.d.ts +16 -1
  57. package/dist/integrations/gitlab/api.d.ts.map +1 -1
  58. package/dist/integrations/gitlab/api.js +9 -0
  59. package/dist/integrations/gitlab/api.js.map +1 -1
  60. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  61. package/dist/integrations/gitlab/routes.js +10 -6
  62. package/dist/integrations/gitlab/routes.js.map +1 -1
  63. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  64. package/dist/integrations/gitlab/rules.js +28 -21
  65. package/dist/integrations/gitlab/rules.js.map +1 -1
  66. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -1
  67. package/dist/integrations/gitlab/session-subscriptions.js +1 -2
  68. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
  69. package/dist/integrations/gitlab/subscriptions.d.ts +7 -4
  70. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -1
  71. package/dist/integrations/gitlab/subscriptions.js +5 -5
  72. package/dist/integrations/gitlab/subscriptions.js.map +1 -1
  73. package/dist/integrations/gitlab/version-control.d.ts.map +1 -1
  74. package/dist/integrations/gitlab/version-control.js +37 -3
  75. package/dist/integrations/gitlab/version-control.js.map +1 -1
  76. package/dist/integrations/incidentio/api.d.ts +9 -0
  77. package/dist/integrations/incidentio/api.d.ts.map +1 -1
  78. package/dist/integrations/incidentio/api.js +3 -0
  79. package/dist/integrations/incidentio/api.js.map +1 -1
  80. package/dist/integrations/incidentio/intake.d.ts +1 -1
  81. package/dist/integrations/incidentio/intake.d.ts.map +1 -1
  82. package/dist/integrations/incidentio/intake.js.map +1 -1
  83. package/dist/integrations/incidentio/integration.d.ts.map +1 -1
  84. package/dist/integrations/incidentio/integration.js +1 -0
  85. package/dist/integrations/incidentio/integration.js.map +1 -1
  86. package/dist/integrations/jira/api.d.ts +7 -0
  87. package/dist/integrations/jira/api.d.ts.map +1 -1
  88. package/dist/integrations/jira/api.js +4 -0
  89. package/dist/integrations/jira/api.js.map +1 -1
  90. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  91. package/dist/integrations/linear/agent-tools.js.map +1 -1
  92. package/dist/integrations/platform/api-client.d.ts +6 -0
  93. package/dist/integrations/platform/api-client.d.ts.map +1 -1
  94. package/dist/integrations/platform/api-client.js +6 -1
  95. package/dist/integrations/platform/api-client.js.map +1 -1
  96. package/dist/integrations/platform/connect/routes.d.ts +1 -1
  97. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  98. package/dist/integrations/platform/connect/routes.js.map +1 -1
  99. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  100. package/dist/integrations/platform/github/integration.js +27 -1
  101. package/dist/integrations/platform/github/integration.js.map +1 -1
  102. package/dist/integrations/platform/incidentio/integration.d.ts +1 -1
  103. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
  104. package/dist/integrations/platform/incidentio/integration.js +1 -0
  105. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  106. package/dist/integrations/platform/jira/integration.d.ts +1 -1
  107. package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
  108. package/dist/integrations/platform/jira/integration.js +1 -0
  109. package/dist/integrations/platform/jira/integration.js.map +1 -1
  110. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  111. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  112. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  113. package/dist/integrations/slack/integration.d.ts.map +1 -1
  114. package/dist/integrations/slack/integration.js +33 -6
  115. package/dist/integrations/slack/integration.js.map +1 -1
  116. package/dist/integrations/slack/slack.d.ts +16 -5
  117. package/dist/integrations/slack/slack.d.ts.map +1 -1
  118. package/dist/integrations/slack/slack.js +137 -64
  119. package/dist/integrations/slack/slack.js.map +1 -1
  120. package/dist/integrations/subscription-session.d.ts +14 -0
  121. package/dist/integrations/subscription-session.d.ts.map +1 -1
  122. package/dist/integrations/subscription-session.js +30 -16
  123. package/dist/integrations/subscription-session.js.map +1 -1
  124. package/dist/mcp/disconnect.d.ts +10 -0
  125. package/dist/mcp/disconnect.d.ts.map +1 -0
  126. package/dist/mcp/disconnect.js +44 -0
  127. package/dist/mcp/disconnect.js.map +1 -0
  128. package/dist/mcp/routes.d.ts +46 -0
  129. package/dist/mcp/routes.d.ts.map +1 -0
  130. package/dist/mcp/routes.js +243 -0
  131. package/dist/mcp/routes.js.map +1 -0
  132. package/dist/provider-display-name.d.ts +2 -0
  133. package/dist/provider-display-name.d.ts.map +1 -0
  134. package/dist/provider-display-name.js +16 -0
  135. package/dist/provider-display-name.js.map +1 -0
  136. package/dist/review-verdict.d.ts +11 -0
  137. package/dist/review-verdict.d.ts.map +1 -1
  138. package/dist/review-verdict.js +16 -1
  139. package/dist/review-verdict.js.map +1 -1
  140. package/dist/routes/attention-activity.d.ts.map +1 -1
  141. package/dist/routes/attention-activity.js +5 -2
  142. package/dist/routes/attention-activity.js.map +1 -1
  143. package/dist/routes/attention-providers.d.ts +0 -1
  144. package/dist/routes/attention-providers.d.ts.map +1 -1
  145. package/dist/routes/attention-providers.js +5 -6
  146. package/dist/routes/attention-providers.js.map +1 -1
  147. package/dist/routes/config.d.ts +44 -5
  148. package/dist/routes/config.d.ts.map +1 -1
  149. package/dist/routes/config.js +181 -58
  150. package/dist/routes/config.js.map +1 -1
  151. package/dist/routes/contracts.d.ts +4 -0
  152. package/dist/routes/contracts.d.ts.map +1 -1
  153. package/dist/routes/contracts.js +3 -1
  154. package/dist/routes/contracts.js.map +1 -1
  155. package/dist/routes/custom-provider-source.d.ts +8 -0
  156. package/dist/routes/custom-provider-source.d.ts.map +1 -1
  157. package/dist/routes/custom-provider-source.js +22 -1
  158. package/dist/routes/custom-provider-source.js.map +1 -1
  159. package/dist/routes/oauth.js +1 -1
  160. package/dist/routes/oauth.js.map +1 -1
  161. package/dist/routes/projects.d.ts +1 -1
  162. package/dist/routes/projects.d.ts.map +1 -1
  163. package/dist/routes/projects.js +1 -1
  164. package/dist/routes/projects.js.map +1 -1
  165. package/dist/routes/provider-credentials.d.ts +7 -2
  166. package/dist/routes/provider-credentials.d.ts.map +1 -1
  167. package/dist/routes/provider-credentials.js +30 -8
  168. package/dist/routes/provider-credentials.js.map +1 -1
  169. package/dist/routes/skills.d.ts +2 -4
  170. package/dist/routes/skills.d.ts.map +1 -1
  171. package/dist/routes/skills.js +19 -65
  172. package/dist/routes/skills.js.map +1 -1
  173. package/dist/routes/source-control-sessions.d.ts +9 -1
  174. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  175. package/dist/routes/source-control-sessions.js +131 -7
  176. package/dist/routes/source-control-sessions.js.map +1 -1
  177. package/dist/routes/surface.d.ts +3 -2
  178. package/dist/routes/surface.d.ts.map +1 -1
  179. package/dist/routes/surface.js +7 -3
  180. package/dist/routes/surface.js.map +1 -1
  181. package/dist/routes/work-items.d.ts.map +1 -1
  182. package/dist/routes/work-items.js +60 -120
  183. package/dist/routes/work-items.js.map +1 -1
  184. package/dist/rules/binding-context.js +7 -7
  185. package/dist/rules/binding-context.js.map +1 -1
  186. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  187. package/dist/rules/dispatch-errors.js +12 -0
  188. package/dist/rules/dispatch-errors.js.map +1 -1
  189. package/dist/rules/dispatcher.d.ts +8 -1
  190. package/dist/rules/dispatcher.d.ts.map +1 -1
  191. package/dist/rules/dispatcher.js +117 -12
  192. package/dist/rules/dispatcher.js.map +1 -1
  193. package/dist/rules/processor.d.ts.map +1 -1
  194. package/dist/rules/processor.js +2 -1
  195. package/dist/rules/processor.js.map +1 -1
  196. package/dist/rules/start-coordinator.d.ts +4 -0
  197. package/dist/rules/start-coordinator.d.ts.map +1 -1
  198. package/dist/rules/start-coordinator.js +36 -4
  199. package/dist/rules/start-coordinator.js.map +1 -1
  200. package/dist/rules/tools.d.ts.map +1 -1
  201. package/dist/rules/tools.js +82 -3
  202. package/dist/rules/tools.js.map +1 -1
  203. package/dist/rules/transition-service.d.ts +17 -0
  204. package/dist/rules/transition-service.d.ts.map +1 -1
  205. package/dist/rules/transition-service.js +25 -0
  206. package/dist/rules/transition-service.js.map +1 -1
  207. package/dist/rules/types.d.ts +2 -4
  208. package/dist/rules/types.d.ts.map +1 -1
  209. package/dist/rules/types.js +1 -4
  210. package/dist/rules/types.js.map +1 -1
  211. package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -1
  212. package/dist/sandbox/local-factory-sandbox.js +1 -0
  213. package/dist/sandbox/local-factory-sandbox.js.map +1 -1
  214. package/dist/sandbox/session-retirement.d.ts +27 -3
  215. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  216. package/dist/sandbox/session-retirement.js +158 -20
  217. package/dist/sandbox/session-retirement.js.map +1 -1
  218. package/dist/secret-encryption.d.ts.map +1 -1
  219. package/dist/secret-encryption.js +65 -25
  220. package/dist/secret-encryption.js.map +1 -1
  221. package/dist/session/channel-reply-processor.d.ts +36 -0
  222. package/dist/session/channel-reply-processor.d.ts.map +1 -0
  223. package/dist/session/channel-reply-processor.js +46 -0
  224. package/dist/session/channel-reply-processor.js.map +1 -0
  225. package/dist/session/channel-session-link-processor.d.ts +39 -0
  226. package/dist/session/channel-session-link-processor.d.ts.map +1 -0
  227. package/dist/session/channel-session-link-processor.js +100 -0
  228. package/dist/session/channel-session-link-processor.js.map +1 -0
  229. package/dist/session/credential-policy.d.ts +1 -1
  230. package/dist/session/credential-policy.d.ts.map +1 -1
  231. package/dist/session/credential-policy.js +7 -6
  232. package/dist/session/credential-policy.js.map +1 -1
  233. package/dist/session/default-model-hydration.d.ts +1 -0
  234. package/dist/session/default-model-hydration.d.ts.map +1 -1
  235. package/dist/session/default-model-hydration.js +3 -2
  236. package/dist/session/default-model-hydration.js.map +1 -1
  237. package/dist/session/environment-state-processor.js +1 -1
  238. package/dist/session/environment-state-processor.js.map +1 -1
  239. package/dist/session/factory-session.d.ts +19 -1
  240. package/dist/session/factory-session.d.ts.map +1 -1
  241. package/dist/session/factory-session.js +5 -2
  242. package/dist/session/factory-session.js.map +1 -1
  243. package/dist/session/filesystem-capture.d.ts +3 -3
  244. package/dist/session/filesystem-capture.d.ts.map +1 -1
  245. package/dist/session/filesystem-capture.js +16 -17
  246. package/dist/session/filesystem-capture.js.map +1 -1
  247. package/dist/session/first-exec-capture.d.ts +1 -1
  248. package/dist/session/first-exec-capture.d.ts.map +1 -1
  249. package/dist/session/first-exec-capture.js +1 -1
  250. package/dist/session/first-exec-capture.js.map +1 -1
  251. package/dist/session/first-message-capture.d.ts +1 -1
  252. package/dist/session/first-message-capture.d.ts.map +1 -1
  253. package/dist/session/first-message-capture.js +1 -1
  254. package/dist/session/first-message-capture.js.map +1 -1
  255. package/dist/session/live-sessions.d.ts +1 -1
  256. package/dist/session/live-sessions.js +1 -1
  257. package/dist/session/live-sessions.js.map +1 -1
  258. package/dist/session/memory-settings-hydration.d.ts +1 -1
  259. package/dist/session/memory-settings-hydration.d.ts.map +1 -1
  260. package/dist/session/memory-settings-hydration.js +1 -1
  261. package/dist/session/memory-settings-hydration.js.map +1 -1
  262. package/dist/session/reply-credential-processor.d.ts +15 -0
  263. package/dist/session/reply-credential-processor.d.ts.map +1 -0
  264. package/dist/session/reply-credential-processor.js +38 -0
  265. package/dist/session/reply-credential-processor.js.map +1 -0
  266. package/dist/session/resource-migration.d.ts +87 -0
  267. package/dist/session/resource-migration.d.ts.map +1 -0
  268. package/dist/session/resource-migration.js +163 -0
  269. package/dist/session/resource-migration.js.map +1 -0
  270. package/dist/session/run-audit.d.ts +24 -0
  271. package/dist/session/run-audit.d.ts.map +1 -1
  272. package/dist/session/run-audit.js +93 -7
  273. package/dist/session/run-audit.js.map +1 -1
  274. package/dist/session/session-threads.d.ts +49 -0
  275. package/dist/session/session-threads.d.ts.map +1 -0
  276. package/dist/session/session-threads.js +70 -0
  277. package/dist/session/session-threads.js.map +1 -0
  278. package/dist/session/source-control-tools.d.ts +19 -1
  279. package/dist/session/source-control-tools.d.ts.map +1 -1
  280. package/dist/session/source-control-tools.js +78 -11
  281. package/dist/session/source-control-tools.js.map +1 -1
  282. package/dist/session/thinking-default.d.ts.map +1 -1
  283. package/dist/session/thinking-default.js +3 -4
  284. package/dist/session/thinking-default.js.map +1 -1
  285. package/dist/session/thread-session-stamp.d.ts +21 -0
  286. package/dist/session/thread-session-stamp.d.ts.map +1 -0
  287. package/dist/session/thread-session-stamp.js +20 -0
  288. package/dist/session/thread-session-stamp.js.map +1 -0
  289. package/dist/session/thread-title-mirror.d.ts +1 -1
  290. package/dist/session/thread-title-mirror.d.ts.map +1 -1
  291. package/dist/session/thread-title-mirror.js +1 -1
  292. package/dist/session/thread-title-mirror.js.map +1 -1
  293. package/dist/session/work-item-repository.d.ts +1 -1
  294. package/dist/session/work-item-repository.d.ts.map +1 -1
  295. package/dist/session/work-item-repository.js.map +1 -1
  296. package/dist/skills/service.d.ts +6 -8
  297. package/dist/skills/service.d.ts.map +1 -1
  298. package/dist/skills/service.js +3 -3
  299. package/dist/skills/service.js.map +1 -1
  300. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -1
  301. package/dist/storage/domains/audit/agent-audit.js +2 -2
  302. package/dist/storage/domains/audit/agent-audit.js.map +1 -1
  303. package/dist/storage/domains/audit/domain.js +1 -1
  304. package/dist/storage/domains/filesystem/base.d.ts +4 -0
  305. package/dist/storage/domains/filesystem/base.d.ts.map +1 -1
  306. package/dist/storage/domains/filesystem/base.js +5 -0
  307. package/dist/storage/domains/filesystem/base.js.map +1 -1
  308. package/dist/storage/domains/integrations/base.d.ts +8 -0
  309. package/dist/storage/domains/integrations/base.d.ts.map +1 -1
  310. package/dist/storage/domains/integrations/base.js +7 -0
  311. package/dist/storage/domains/integrations/base.js.map +1 -1
  312. package/dist/storage/domains/projects/base.d.ts +6 -0
  313. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  314. package/dist/storage/domains/projects/base.js +12 -0
  315. package/dist/storage/domains/projects/base.js.map +1 -1
  316. package/dist/storage/domains/source-control/base.d.ts +28 -0
  317. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  318. package/dist/storage/domains/source-control/base.js +48 -0
  319. package/dist/storage/domains/source-control/base.js.map +1 -1
  320. package/dist/storage/domains/source-control/inmemory.d.ts +8 -0
  321. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  322. package/dist/storage/domains/source-control/inmemory.js +13 -1
  323. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  324. package/dist/storage/domains/work-items/base.d.ts +79 -7
  325. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  326. package/dist/storage/domains/work-items/base.js +172 -30
  327. package/dist/storage/domains/work-items/base.js.map +1 -1
  328. package/dist/timing.d.ts +23 -0
  329. package/dist/timing.d.ts.map +1 -1
  330. package/dist/timing.js +85 -6
  331. package/dist/timing.js.map +1 -1
  332. package/dist/tools/annotations.d.ts +7 -0
  333. package/dist/tools/annotations.d.ts.map +1 -0
  334. package/dist/tools/annotations.js +102 -0
  335. package/dist/tools/annotations.js.map +1 -0
  336. package/dist/tools/approval-tools.d.ts +15 -0
  337. package/dist/tools/approval-tools.d.ts.map +1 -0
  338. package/dist/tools/approval-tools.js +79 -0
  339. package/dist/tools/approval-tools.js.map +1 -0
  340. package/dist/tools/deliver.d.ts +71 -0
  341. package/dist/tools/deliver.d.ts.map +1 -0
  342. package/dist/tools/deliver.js +129 -0
  343. package/dist/tools/deliver.js.map +1 -0
  344. package/dist/tools/index.d.ts +30 -0
  345. package/dist/tools/index.d.ts.map +1 -0
  346. package/dist/tools/index.js +36 -0
  347. package/dist/tools/index.js.map +1 -0
  348. package/dist/tools/messaging-tools.d.ts +28 -0
  349. package/dist/tools/messaging-tools.d.ts.map +1 -0
  350. package/dist/tools/messaging-tools.js +396 -0
  351. package/dist/tools/messaging-tools.js.map +1 -0
  352. package/dist/tools/permissions.d.ts +31 -0
  353. package/dist/tools/permissions.d.ts.map +1 -0
  354. package/dist/tools/permissions.js +48 -0
  355. package/dist/tools/permissions.js.map +1 -0
  356. package/dist/tools/read-tools.d.ts +30 -0
  357. package/dist/tools/read-tools.d.ts.map +1 -0
  358. package/dist/tools/read-tools.js +293 -0
  359. package/dist/tools/read-tools.js.map +1 -0
  360. package/dist/tools/reports.d.ts +174 -0
  361. package/dist/tools/reports.d.ts.map +1 -0
  362. package/dist/tools/reports.js +380 -0
  363. package/dist/tools/reports.js.map +1 -0
  364. package/dist/tools/run-watch.d.ts +46 -0
  365. package/dist/tools/run-watch.d.ts.map +1 -0
  366. package/dist/tools/run-watch.js +102 -0
  367. package/dist/tools/run-watch.js.map +1 -0
  368. package/dist/tools/scope.d.ts +54 -0
  369. package/dist/tools/scope.d.ts.map +1 -0
  370. package/dist/tools/scope.js +87 -0
  371. package/dist/tools/scope.js.map +1 -0
  372. package/dist/tools/session-tools.d.ts +43 -0
  373. package/dist/tools/session-tools.d.ts.map +1 -0
  374. package/dist/tools/session-tools.js +410 -0
  375. package/dist/tools/session-tools.js.map +1 -0
  376. package/dist/tools/sessions-state-processor.d.ts +41 -0
  377. package/dist/tools/sessions-state-processor.d.ts.map +1 -0
  378. package/dist/tools/sessions-state-processor.js +190 -0
  379. package/dist/tools/sessions-state-processor.js.map +1 -0
  380. package/dist/tools/side-sessions.d.ts +53 -0
  381. package/dist/tools/side-sessions.d.ts.map +1 -0
  382. package/dist/tools/side-sessions.js +83 -0
  383. package/dist/tools/side-sessions.js.map +1 -0
  384. package/dist/tools/work-item-tools.d.ts +28 -0
  385. package/dist/tools/work-item-tools.d.ts.map +1 -0
  386. package/dist/tools/work-item-tools.js +342 -0
  387. package/dist/tools/work-item-tools.js.map +1 -0
  388. package/dist/work-items/create-work-item.d.ts +55 -0
  389. package/dist/work-items/create-work-item.d.ts.map +1 -0
  390. package/dist/work-items/create-work-item.js +101 -0
  391. package/dist/work-items/create-work-item.js.map +1 -0
  392. package/dist/work-items/decision-actions.d.ts +42 -0
  393. package/dist/work-items/decision-actions.d.ts.map +1 -0
  394. package/dist/work-items/decision-actions.js +70 -0
  395. package/dist/work-items/decision-actions.js.map +1 -0
  396. package/dist/workspace.d.ts +1 -1
  397. package/dist/workspace.d.ts.map +1 -1
  398. package/dist/workspace.js +15 -7
  399. package/dist/workspace.js.map +1 -1
  400. package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
  401. package/factory-skills/factory-gitlab-review/SKILL.md +1 -1
  402. package/factory-skills/factory-plan/SKILL.md +4 -4
  403. package/factory-skills/factory-rereview/SKILL.md +3 -1
  404. package/factory-skills/factory-review/SKILL.md +3 -1
  405. package/factory-skills/factory-self-review/SKILL.md +46 -0
  406. package/package.json +15 -15
@@ -25,8 +25,8 @@ import type { MemorySettingsStorage } from '../storage/domains/memory-settings/b
25
25
  import type { ModelDefaultsStorage } from '../storage/domains/model-defaults/base.js';
26
26
  import type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';
27
27
  import type { QueueHealthStorage } from '../storage/domains/queue-health/base.js';
28
- import { type SourceControlStorage, type SourceControlStorageHandle } from '../storage/domains/source-control/base.js';
29
- import { type WorkItemsStorage } from '../storage/domains/work-items/base.js';
28
+ import type { SourceControlStorage, SourceControlStorageHandle } from '../storage/domains/source-control/base.js';
29
+ import type { WorkItemsStorage } from '../storage/domains/work-items/base.js';
30
30
  import type { RouteAuth } from './route.js';
31
31
  export interface IntegrationRegistration {
32
32
  integration: FactoryIntegration;
@@ -86,6 +86,7 @@ export interface FactoryApiRoutesDeps {
86
86
  sessionRetirement?: import('../sandbox/session-retirement.js').SessionRetirementCoordinator;
87
87
  onFactoryRuntime?: (runtime: {
88
88
  transitionService: FactoryTransitionService;
89
+ startCoordinator: FactoryStartCoordinator;
89
90
  prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;
90
91
  }) => void;
91
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../../src/routes/surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAG/E,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAQ1E,OAAO,KAAK,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;IACF,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC;IACtB,qFAAqF;IACrF,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,IAAI,CACX,oBAAoB,CAAC,SAAS,CAAC,EAC/B,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,eAAe,CAC7F,CAAC;IACF;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,EACD,aAAa,EAAE,MAAM,GACpB,kBAAkB,CAuCpB;AAiGD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,QAAQ,EAAE,CA2N/E"}
@@ -7,12 +7,13 @@ import { isAgentActor } from "../storage/domains/work-items/base.js";
7
7
  import { getGithubFeatureDiagnostics } from "../integrations/github/config.js";
8
8
  import { invalidateTenantCredentialSnapshots } from "./tenant-credentials.js";
9
9
  import { effectiveModelScope } from "../storage/domains/projects/base.js";
10
- import { ConfigRoutes } from "./config.js";
11
- import { invalidateCustomProvidersSnapshots } from "./custom-provider-source.js";
12
10
  import { SessionOwnershipMismatchError, SourceControlConnectionNotFoundError } from "../storage/domains/source-control/base.js";
13
11
  import { FactorySourceSessionResolutionError, createSourceControlSessionLookup, ensureFactorySourceSession, resolveFactorySourceControl } from "../session/factory-session.js";
12
+ import { ConfigRoutes } from "./config.js";
13
+ import { buildSourceControlSessionRoutes } from "./source-control-sessions.js";
14
14
  import { resolveWorkItemRepository } from "../session/work-item-repository.js";
15
15
  import { FactoryStartCoordinator } from "../rules/start-coordinator.js";
16
+ import { invalidateCustomProvidersSnapshots } from "./custom-provider-source.js";
16
17
  import { FactoryTransitionService } from "../rules/transition-service.js";
17
18
  import { buildAutomationRunRoutes } from "./automation-runs.js";
18
19
  import { buildFsRoutes } from "./fs.js";
@@ -20,7 +21,6 @@ import { IntakeRoutes } from "./intake.js";
20
21
  import { KnowledgeRoutes } from "./knowledge.js";
21
22
  import { OAuthRoutes } from "./oauth.js";
22
23
  import { SkillRoutes } from "./skills.js";
23
- import { buildSourceControlSessionRoutes } from "./source-control-sessions.js";
24
24
  import { buildSourceControlSettingsRoutes } from "./source-control-settings.js";
25
25
  import { WorkItemRoutes } from "./work-items.js";
26
26
  import { registerApiRoute } from "@mastra/core/server";
@@ -387,6 +387,8 @@ function assembleFactoryApiRoutes(deps) {
387
387
  controller: deps.controller,
388
388
  memorySettings: deps.domains.memorySettings,
389
389
  sessionRetirement: deps.sessionRetirement,
390
+ sandboxRecreateSupported: deps.sandbox !== void 0 && deps.sandbox.provider !== "local",
391
+ filesystem: deps.domains.filesystem,
390
392
  ...deps.factoryReady ? { workItems: deps.domains.workItems } : {},
391
393
  ...githubStorage ? { githubRepositories: githubStorage.repositories } : {}
392
394
  });
@@ -413,6 +415,7 @@ function assembleFactoryApiRoutes(deps) {
413
415
  }) : void 0;
414
416
  if (transitionService && startCoordinator) deps.onFactoryRuntime?.({
415
417
  transitionService,
418
+ startCoordinator,
416
419
  ...sourceControlRegistrations.length > 0 ? { prepareBinding: async (input) => {
417
420
  const sourceControl = await resolveFactorySourceControl({
418
421
  sourceControls,
@@ -439,6 +442,7 @@ function assembleFactoryApiRoutes(deps) {
439
442
  modelCredentials: deps.domains.modelCredentials,
440
443
  modelDefaults: deps.domains.modelDefaults,
441
444
  sourceControlSessions,
445
+ sourceControls,
442
446
  workItems: deps.domains.workItems,
443
447
  memorySettings: deps.domains.memorySettings,
444
448
  factoryProjects: deps.domains.projects,
@@ -1 +1 @@
1
- {"version":3,"file":"surface.js","names":[],"sources":["../../src/routes/surface.ts"],"sourcesContent":["import type { AuthStorage } from '@mastra/code-sdk/auth/storage';\nimport type { MastraCodeState } from '@mastra/code-sdk/schema';\nimport type { AgentController } from '@mastra/core/agent-controller';\nimport type { ApiRoute, IUserProvider } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { FactoryStorage } from '@mastra/core/storage';\nimport type { FactorySandbox } from '@mastra/core/workspace';\n\nimport { boardForWorkItem } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationHooks } from '../integrations/base.js';\nimport { getGithubFeatureDiagnostics } from '../integrations/github/config.js';\nimport type { GithubIntegration } from '../integrations/github/integration.js';\nimport { MaterializeError } from '../integrations/github/sandbox.js';\nimport { FactoryDispatchError } from '../rules/dispatch-errors.js';\nimport type { FactoryBindingPreparationInput } from '../rules/dispatcher.js';\nimport { FactoryStartCoordinator } from '../rules/start-coordinator.js';\nimport { FactoryTransitionService } from '../rules/transition-service.js';\nimport {\n createSourceControlSessionLookup,\n ensureFactorySourceSession,\n FactorySourceSessionResolutionError,\n resolveFactorySourceControl,\n} from '../session/factory-session.js';\nimport type { EnsuredFactorySourceSession } from '../session/factory-session.js';\nimport type { LiveSessions } from '../session/live-sessions.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { StateSigner } from '../state-signing.js';\nimport type { AuditEmitter, AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { ChannelIdentityStorage } from '../storage/domains/channel-identity/base.js';\nimport type { WorkItemCommentsStorage } from '../storage/domains/comments/base.js';\nimport type { CommentsDomain } from '../storage/domains/comments/domain.js';\nimport type { ModelCredentialsStorage } from '../storage/domains/credentials/base.js';\nimport type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport type { FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { IntakeStorage } from '../storage/domains/intake/base.js';\nimport type { IntegrationStorage } from '../storage/domains/integrations/base.js';\nimport type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js';\nimport type { ModelDefaultsStorage } from '../storage/domains/model-defaults/base.js';\nimport { effectiveModelScope } from '../storage/domains/projects/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { QueueHealthStorage } from '../storage/domains/queue-health/base.js';\nimport {\n SessionOwnershipMismatchError,\n SourceControlConnectionNotFoundError,\n type SourceControlStorage,\n type SourceControlStorageHandle,\n} from '../storage/domains/source-control/base.js';\nimport {\n isAgentActor,\n type FactoryDispatchFailureCode,\n type WorkItemsStorage,\n} from '../storage/domains/work-items/base.js';\nimport { workItemBranch, workItemBranchSource, workItemThreadTitle } from '../work-item-branch.js';\nimport { buildAutomationRunRoutes } from './automation-runs.js';\nimport { ConfigRoutes } from './config.js';\nimport { invalidateCustomProvidersSnapshots } from './custom-provider-source.js';\nimport { buildFsRoutes } from './fs.js';\nimport { IntakeRoutes } from './intake.js';\nimport { KnowledgeRoutes } from './knowledge.js';\nimport { OAuthRoutes } from './oauth.js';\nimport type { RouteAuth } from './route.js';\nimport { SkillRoutes } from './skills.js';\nimport { buildSourceControlSessionRoutes } from './source-control-sessions.js';\nimport { buildSourceControlSettingsRoutes } from './source-control-settings.js';\nimport { invalidateTenantCredentialSnapshots } from './tenant-credentials.js';\nimport { WorkItemRoutes } from './work-items.js';\n\nconst MATERIALIZE_FAILURE_CODE = {\n 'git-missing': 'repository_git_missing',\n 'egress-blocked': 'repository_egress_blocked',\n 'clone-failed': 'repository_clone_failed',\n 'pull-failed': 'repository_pull_failed',\n 'push-failed': 'repository_push_failed',\n 'commit-failed': 'repository_commit_failed',\n 'gh-missing': 'repository_cli_missing',\n 'pr-failed': 'repository_pr_failed',\n} satisfies Record<MaterializeError['code'], FactoryDispatchFailureCode>;\nexport interface IntegrationRegistration {\n integration: FactoryIntegration;\n ready: boolean;\n ensureReady: () => Promise<void>;\n}\n\nexport interface FactoryApiRoutesDeps {\n controllerId: string;\n controller: AgentController<MastraCodeState>;\n /** Registry of the sessions this process holds, owned by the host so it can watch them too. */\n liveSessions: LiveSessions;\n /** Request-auth seam threaded from the host (no service locator). */\n auth: RouteAuth;\n /** Optional user directory for resolving persisted owners to display profiles. */\n users?: Pick<IUserProvider, 'getUser' | 'getUsers'>;\n authStorage: AuthStorage;\n audit: AuditEmitter & AuditRecorder;\n fsRoot?: string;\n publicOrigin: string;\n stateSigner?: StateSigner;\n /** Sandbox surface (enablement, provider label, create callback). */\n sandbox?: FactorySandbox;\n /** Push hand-off for environment builds, present when the sandbox can build templates. */\n onRepositoryPush?: IntegrationHooks['onRepositoryPush'];\n /** Root factory storage backend (distributed locks, app-db diagnostics). */\n factoryStorage?: FactoryStorage;\n integrationStorage: IntegrationStorage;\n sourceControlStorage: SourceControlStorage;\n /** App-table domain handles, registered and owned by `MastraFactory.prepare()`. */\n domains: {\n intake: IntakeStorage;\n modelCredentials: ModelCredentialsStorage;\n memorySettings: MemorySettingsStorage;\n customProviders: CustomProvidersStorage;\n filesystem: FilesystemStorage;\n modelDefaults: ModelDefaultsStorage;\n projects: FactoryProjectsStorage;\n queueHealth: QueueHealthStorage;\n workItems: WorkItemsStorage;\n channelIdentity: ChannelIdentityStorage;\n comments: WorkItemCommentsStorage;\n };\n integrations?: IntegrationRegistration[];\n intakeReady: boolean;\n factoryReady: boolean;\n knowledgeEnabled: boolean;\n /** Providers the operator opted in to run on the server process's own credentials. */\n deploymentModelProviders?: ReadonlySet<string>;\n knowledgeKey?: string;\n /** Resolved Factory rule set, threaded from the host (no service locator). */\n configVersion: string;\n /** Boards installed for this Factory instance. */\n boardRegistry: BoardRegistry;\n /** Work-item feed service, handed to integrations that ingest platform messages. */\n feed: CommentsDomain;\n factoryTransitionService?: FactoryTransitionService;\n sessionRetirement?: import('../sandbox/session-retirement.js').SessionRetirementCoordinator;\n onFactoryRuntime?: (runtime: {\n transitionService: FactoryTransitionService;\n prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;\n }) => void;\n}\n\nfunction guardIntegrationRoutes({\n integration,\n ready,\n ensureReady,\n routes,\n}: IntegrationRegistration & { routes: ApiRoute[] }): ApiRoute[] {\n if (ready) return routes;\n return routes.map(route => {\n if ('handler' in route) {\n const handler = route.handler;\n return {\n ...route,\n handler: async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context, async () => {});\n },\n };\n }\n\n const createHandler = route.createHandler;\n return {\n ...route,\n createHandler: async (args: Parameters<typeof createHandler>[0]) => {\n const handler = await createHandler(args);\n return async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context);\n };\n },\n };\n });\n}\n\n/**\n * Resolve the source-control session the work item already holds for this role,\n * when it still resolves to the item's org and factory project. Returns\n * `undefined` when there is no ref or the ref no longer resolves, so the caller\n * falls back to minting one.\n */\nasync function reuseBoundSession(\n sourceControl: SourceControlStorageHandle,\n input: FactoryBindingPreparationInput,\n role: string = input.role,\n): Promise<EnsuredFactorySourceSession | undefined> {\n const ref = input.item.sessions[role];\n if (!ref) return undefined;\n // At least as strict as the coordinator's resolveSourceSession: a ref it\n // would reject must fall through to minting, not hard-fail the run.\n const session = await sourceControl.sessions.getBySessionId(ref.sessionId);\n if (\n !session?.projectRepositoryId ||\n session.orgId !== input.record.orgId ||\n session.factoryProjectId !== input.record.factoryProjectId\n ) {\n return undefined;\n }\n return {\n sessionId: session.sessionId,\n userId: session.userId,\n projectRepositoryId: session.projectRepositoryId,\n branch: session.branch,\n baseBranch: session.baseBranch,\n };\n}\n\n/** Roles whose sessions a later role may continue in, newest stage first. */\nconst INHERITABLE_ROLE_FALLBACK = ['plan', 'triage'];\n\n/**\n * A role running for the first time continues in the card's latest earlier\n * session on the same branch, so a build approved by someone other than the\n * plan's owner keeps the plan's context instead of starting empty. Review is\n * independent by design and never inherits.\n */\nasync function inheritEarlierSession(\n sourceControl: SourceControlStorageHandle,\n input: FactoryBindingPreparationInput,\n board: { roleForPhase(phase: string): string | undefined } | undefined,\n branch: string,\n projectRepositoryId: string,\n): Promise<EnsuredFactorySourceSession | undefined> {\n if (input.role === 'review') return undefined;\n // The card's linked repository can change after an earlier role ran; only\n // continue in a session on the repository a fresh session would use.\n const candidates: string[] = [];\n for (const entry of [...(input.item.stageHistory ?? [])].reverse()) {\n const role = board?.roleForPhase(entry.stage);\n if (role && role !== input.role && role !== 'review' && !candidates.includes(role)) candidates.push(role);\n }\n for (const role of INHERITABLE_ROLE_FALLBACK) {\n if (role !== input.role && !candidates.includes(role)) candidates.push(role);\n }\n for (const role of candidates) {\n const session = await reuseBoundSession(sourceControl, input, role);\n if (session && session.branch === branch && session.projectRepositoryId === projectRepositoryId) {\n return session;\n }\n }\n return undefined;\n}\n\n/**\n * Start a factory run for a rule binding: ensure the source-control session the\n * coordinator requires, then hand it to `prepare` along with the factory's\n * default model. Exported for tests — this is the autonomous entry point with no\n * browser and no interactive user, so nothing else would catch a regression in\n * what it forwards.\n */\nexport async function prepareFactoryRuleBinding(\n sourceControlProvider: SourceControlStorageHandle | Pick<GithubIntegration, 'sourceControlStorage'>,\n coordinator: Pick<FactoryStartCoordinator, 'prepare'>,\n projects: FactoryProjectsStorage,\n boards: BoardRegistry,\n input: FactoryBindingPreparationInput,\n intake?: Pick<IntakeStorage, 'getConfig'>,\n): Promise<void> {\n try {\n const sourceControl =\n 'sourceControlStorage' in sourceControlProvider\n ? sourceControlProvider.sourceControlStorage\n : sourceControlProvider;\n const source = workItemBranchSource(input.item.externalSource);\n const branch = workItemBranch({ id: input.item.id, source, metadata: input.item.metadata });\n // Only leaving a resting phase derives a lane from the role: roles don't own lanes,\n // and the Done close-out running in the triage seat must not drag the card back.\n // Both the current phase and the role's lane come from the installed board; an\n // unknown board or phase yields no destination rather than a guessed one.\n const board = boards.get(boardForWorkItem(input.item));\n const currentStage = input.item.stages.length === 1 ? input.item.stages[0] : undefined;\n const currentKind = currentStage === undefined ? undefined : board?.phaseKind(currentStage);\n const destinationStage =\n currentKind === undefined\n ? undefined\n : currentKind === 'resting'\n ? board?.phaseForRole(input.role)\n : currentStage;\n if (!destinationStage) {\n throw new FactoryDispatchError(\n 'unsupported_provider_item',\n `Factory skill invocation has no destination lane (role \"${input.role}\", stages [${input.item.stages.join(', ')}]).`,\n );\n }\n const connections = await sourceControl.connections.list({\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n });\n if (!connections.some(connection => connection.integrationId === sourceControl.integrationId)) {\n throw new FactoryDispatchError('source_control_missing', 'Factory source-control connection not found.');\n }\n const project = await projects.getById({ id: input.record.factoryProjectId });\n if (!project || project.orgId !== input.record.orgId) {\n throw new FactoryDispatchError(\n 'session_unavailable',\n `Factory model policy is unavailable for project ${input.record.factoryProjectId}.`,\n );\n }\n // A retry may already own a role session. Check it before treating a\n // repository-less card as ambiguous, but never override an explicit signal.\n const boundSession = await reuseBoundSession(sourceControl, input);\n const intakeConfig = await intake?.getConfig({ orgId: input.record.orgId, integrationIds: ['linear'] });\n let repository = await resolveWorkItemRepository({\n sourceControl,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n item: input.item,\n linearRepositoryMap: intakeConfig?.linear?.repositoryByLinearProject,\n });\n if (repository.status === 'ambiguous' && boundSession) {\n const link = await sourceControl.projectRepositories.get({\n orgId: input.record.orgId,\n id: boundSession.projectRepositoryId,\n });\n const linked =\n link && (await sourceControl.repositories.get({ orgId: input.record.orgId, id: link.repositoryId }));\n if (linked && repository.candidates.includes(linked.slug)) {\n repository = { status: 'resolved', slug: linked.slug, projectRepositoryId: link.id };\n }\n }\n if (repository.status !== 'resolved') {\n const detail =\n repository.status === 'ambiguous'\n ? `Choose one of the linked repositories: ${repository.candidates.join(', ')}.`\n : repository.hint;\n throw new FactoryDispatchError('source_repository_ambiguous', detail);\n }\n // Re-preparing a binding (server restart, retired controller session) must\n // land in the role's existing session: minting a replacement would repoint\n // the work item, flip the session's owner to the approver, and orphan the\n // previous sandbox.\n const approver = input.record.approvedBy ?? undefined;\n if (boundSession && boundSession.projectRepositoryId !== repository.projectRepositoryId) {\n throw new FactoryDispatchError(\n 'source_repository_ambiguous',\n `The existing session is bound to a different repository than ${repository.slug}. Choose the correct repository and retry.`,\n );\n }\n // The session is filed under the card's repository: the sandbox holds\n // every environment repository, but the coordinator, the PR tools and the\n // subscriptions follow the session's link, and the card names which one.\n const preparedSession =\n boundSession ??\n (await inheritEarlierSession(sourceControl, input, board, branch, repository.projectRepositoryId)) ??\n (await ensureFactorySourceSession({\n sourceControl,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n projectRepositoryId: repository.projectRepositoryId,\n branch,\n // A person who approved the run is its interactive user: attribute it to\n // them, not the repo connector. An agent's pre-approval names no person.\n attributeToUserId: isAgentActor(approver) ? undefined : approver,\n }).catch(error => {\n if (error instanceof FactorySourceSessionResolutionError && error.reason === 'repository') {\n // The card resolved to a linked repository the sandbox will not check out.\n throw new FactoryDispatchError(\n 'source_repository_missing',\n `Repository ${repository.slug} is linked but not in this Factory's environment. Turn it on under Settings → Environment, then retry.`,\n { cause: error },\n );\n }\n if (!(error instanceof SessionOwnershipMismatchError)) throw error;\n throw new FactoryDispatchError(\n 'session_unavailable',\n `Session ${error.sessionId} on branch ${branch} predates factory ownership and cannot be reused. Delete that session, then retry.`,\n { cause: error },\n );\n }));\n\n const modelScope = effectiveModelScope(project.modelScope, 'run');\n await coordinator.prepare({\n orgId: input.record.orgId,\n userId: preparedSession.userId,\n factoryProjectId: input.record.factoryProjectId,\n sessionId: preparedSession.sessionId,\n modelScope,\n defaultModelId: modelScope === 'factory' ? (project.defaultModelId ?? undefined) : undefined,\n threadTitle: workItemThreadTitle({ source, title: input.item.title, metadata: input.item.metadata }),\n kickoffKey: input.record.id,\n destinationStage,\n workItem: {\n id: input.item.id,\n role: input.role,\n input: {\n externalSource: input.item.externalSource,\n parentWorkItemId: input.item.parentWorkItemId,\n title: input.item.title,\n stages: ['intake'],\n sessions: input.item.sessions,\n metadata: input.item.metadata,\n },\n },\n });\n } catch (error) {\n if (error instanceof FactoryDispatchError) throw error;\n if (error instanceof FactorySourceSessionResolutionError) {\n const code = error.reason === 'connection' ? 'source_control_missing' : 'source_repository_missing';\n throw new FactoryDispatchError(code, error.message, { cause: error });\n }\n if (error instanceof SourceControlConnectionNotFoundError) {\n throw new FactoryDispatchError('source_control_missing', error.message, { cause: error });\n }\n if (error instanceof MaterializeError) {\n throw new FactoryDispatchError(MATERIALIZE_FAILURE_CODE[error.code], error.message, { cause: error });\n }\n throw error;\n }\n}\n\n/**\n * Build the {@link IntegrationContext} handed to an integration when the\n * factory collects its capabilities (routes, workers). One shape everywhere:\n * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it\n * when collecting integration workers at finalize.\n */\nexport function buildIntegrationContext(\n deps: Pick<\n FactoryApiRoutesDeps,\n | 'controller'\n | 'publicOrigin'\n | 'auth'\n | 'sandbox'\n | 'users'\n | 'factoryStorage'\n | 'integrationStorage'\n | 'sourceControlStorage'\n | 'integrations'\n > & {\n stateSigner: StateSigner;\n emitAudit?: AuditEmitter['emit'];\n onRepositoryPush?: IntegrationHooks['onRepositoryPush'];\n configVersion: string;\n boardRegistry: BoardRegistry;\n factoryReady: boolean;\n /** Work-item feed service, so a channel integration can ingest platform messages. */\n feed: CommentsDomain;\n domains: Pick<\n FactoryApiRoutesDeps['domains'],\n 'projects' | 'intake' | 'workItems' | 'channelIdentity' | 'memorySettings' | 'modelDefaults'\n >;\n /**\n * Stable id of the registered source-control-owning integration (today:\n * `'github'` when registered). Every call site must derive and pass it so\n * `routes()`, `channels()`, and `workers()` all see the same context shape.\n */\n sourceControlOwnerId?: string;\n },\n integrationId: string,\n): IntegrationContext {\n return {\n auth: deps.auth,\n sandbox: deps.sandbox,\n ...(deps.users ? { users: deps.users } : {}),\n factoryStorage: deps.factoryStorage,\n baseUrl: deps.publicOrigin,\n controller: deps.controller,\n stateSigner: deps.stateSigner,\n storage: {\n generic: deps.integrationStorage.forIntegration(integrationId),\n sourceControl: deps.sourceControlStorage.forIntegration(integrationId),\n ...(deps.sourceControlOwnerId\n ? { sourceControlOwner: deps.sourceControlStorage.forIntegration(deps.sourceControlOwnerId) }\n : {}),\n sourceControls: (deps.integrations ?? [])\n .filter(({ integration }) => integration.versionControl)\n .map(({ integration }) => deps.sourceControlStorage.forIntegration(integration.id)),\n projects: deps.domains.projects,\n intake: deps.domains.intake,\n channelIdentity: deps.domains.channelIdentity,\n memorySettings: deps.domains.memorySettings,\n modelDefaults: deps.domains.modelDefaults,\n },\n ...(deps.factoryReady ? { workItems: deps.domains.workItems, feed: deps.feed } : {}),\n ...(deps.factoryReady\n ? {\n runtime: { configVersion: deps.configVersion, workItems: deps.domains.workItems, boards: deps.boardRegistry },\n }\n : {}),\n ...(deps.emitAudit || deps.onRepositoryPush\n ? {\n hooks: {\n ...(deps.emitAudit ? { emitAudit: deps.emitAudit } : {}),\n ...(deps.onRepositoryPush ? { onRepositoryPush: deps.onRepositoryPush } : {}),\n },\n }\n : {}),\n };\n}\n\n/**\n * Disabled-status stub for the well-known integration ids. The SPA polls\n * `/web/github/status`, `/web/linear/status`, and `/web/jira/status`\n * unconditionally, so when an integration is absent (or not ready) the status\n * contract must still hold. Unknown custom ids get no stub — the SPA doesn't\n * poll them.\n */\nfunction disabledIntegrationStatusRoutes(deps: FactoryApiRoutesDeps, id: string, configured = false): ApiRoute[] {\n if (id === 'github') {\n return [\n registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n installations: [],\n reason: 'missing_config',\n diagnostics: getGithubFeatureDiagnostics({\n github: undefined,\n auth: deps.auth,\n appDbConfigured: deps.factoryStorage !== undefined,\n stateSigner: deps.stateSigner,\n sandbox: deps.sandbox,\n }),\n }),\n }),\n ];\n }\n if (id === 'linear') {\n return [\n registerApiRoute('/web/linear/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n workspace: null,\n reason: 'missing_config',\n diagnostics: {\n linearAppConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: true,\n },\n }),\n }),\n ];\n }\n if (id === 'jira') {\n return [\n registerApiRoute('/web/jira/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n configured,\n site: null,\n reason: 'missing_config',\n diagnostics: {\n jiraConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: deps.factoryStorage !== undefined,\n },\n }),\n }),\n ];\n }\n return [];\n}\n\n/**\n * Stub for `GET /web/channel-accounts` when NO Slack integration is\n * registered. The SPA's Connections section polls the path unconditionally;\n * without a stub the SPA fallback serves HTML, which the UI can only read as\n * \"old server / unknown\". The machine-readable reason lets it say the truth:\n * the integration isn't registered.\n *\n * Mounted only for ABSENT slack — a registered integration owns the path via\n * its connect routes (or, when the state signer is unstable, gets no routes\n * at all and the UI falls back to the generic copy). Static payload, leaks\n * nothing → no auth needed, same posture as the github/linear stubs.\n */\nfunction absentSlackChannelAccountsRoutes(): ApiRoute[] {\n return [\n registerApiRoute('/web/channel-accounts', {\n method: 'GET',\n requiresAuth: false,\n handler: c => c.json({ accounts: [], canConnect: false, reason: 'not_registered' }),\n }),\n ];\n}\n\n/**\n * Assemble the custom `/web/*` API routes as Mastra `server.apiRoutes`:\n * - fs browser routes (project picker), confined to `fsRoot`\n * - config routes (provider/API-key/default-model/OM management)\n * - every registered integration's `routes()` surface (full set when ready,\n * disabled-status stub otherwise), plus stubs for absent known ids\n */\nexport function assembleFactoryApiRoutes(deps: FactoryApiRoutesDeps): ApiRoute[] {\n const emitAudit: AuditEmitter['emit'] = args => deps.audit.emit(args);\n const registrations = deps.integrations ?? [];\n const githubRegistration = registrations.find(({ integration }) => integration.id === 'github');\n const githubStorage = githubRegistration ? deps.sourceControlStorage.forIntegration('github') : undefined;\n const githubIntegration = githubRegistration?.integration as GithubIntegration | undefined;\n const sourceControlRegistrations = registrations.filter(({ integration }) => integration.versionControl);\n const sourceControlIntegrationIds = [\n ...new Set(['github', ...sourceControlRegistrations.map(({ integration }) => integration.id)]),\n ];\n const sourceControls = sourceControlIntegrationIds.map(id => deps.sourceControlStorage.forIntegration(id));\n const sourceControlSessions = createSourceControlSessionLookup(sourceControls);\n\n const integrationRoutes = registrations.flatMap(registration => {\n const { integration } = registration;\n if (!deps.stateSigner) return disabledIntegrationStatusRoutes(deps, integration.id, true);\n const context = buildIntegrationContext(\n {\n ...deps,\n stateSigner: deps.stateSigner,\n emitAudit,\n ...(githubRegistration ? { sourceControlOwnerId: 'github' } : {}),\n },\n integration.id,\n );\n return guardIntegrationRoutes({ ...registration, routes: integration.routes(context) });\n });\n // Session persistence belongs to the linked source-control provider, not to\n // GitHub. Replace legacy GitHub-owned handlers with one resolver spanning\n // the legacy GitHub partition and every registered source-control partition.\n const sharedSessionRouteKeys = new Set([\n 'GET /web/github/projects/:id/sessions',\n 'POST /web/github/projects/:id/sessions',\n 'GET /web/user-sessions/:sessionId',\n 'DELETE /web/user-sessions/:sessionId',\n 'POST /web/user-sessions/:sessionId/title',\n ]);\n const providerRoutes = integrationRoutes.filter(\n route => !sharedSessionRouteKeys.has(route.method + ' ' + route.path),\n );\n const sourceControlSessionRoutes =\n sourceControls.length === 0\n ? []\n : buildSourceControlSessionRoutes({\n auth: deps.auth,\n sourceControls,\n projects: deps.domains.projects,\n ...(deps.users ? { users: deps.users } : {}),\n controller: deps.controller,\n memorySettings: deps.domains.memorySettings,\n sessionRetirement: deps.sessionRetirement,\n ...(deps.factoryReady ? { workItems: deps.domains.workItems } : {}),\n ...(githubStorage ? { githubRepositories: githubStorage.repositories } : {}),\n });\n // Absent known integrations still get their disabled-status stub.\n const absentStubs = ['github', 'linear', 'jira']\n .filter(id => !registrations.some(({ integration }) => integration.id === id))\n .flatMap(id => disabledIntegrationStatusRoutes(deps, id));\n // Absent slack gets the channel-accounts not-registered stub (registered\n // slack owns the path via its own connect routes).\n const slackAbsentStubs = registrations.some(({ integration }) => integration.id === 'slack')\n ? []\n : absentSlackChannelAccountsRoutes();\n\n const transitionService = deps.factoryReady\n ? (deps.factoryTransitionService ??\n new FactoryTransitionService({\n configVersion: deps.configVersion,\n boards: deps.boardRegistry,\n storage: deps.domains.workItems,\n audit: deps.audit,\n }))\n : undefined;\n const startCoordinator = transitionService\n ? new FactoryStartCoordinator(\n deps.controller,\n deps.domains.workItems,\n transitionService,\n request =>\n resolveFactorySourceControl({\n sourceControls,\n orgId: request.orgId,\n factoryProjectId: request.factoryProjectId,\n sessionId: request.sessionId,\n }),\n deps.domains.intake,\n { projects: deps.domains.projects, modelDefaults: deps.domains.modelDefaults },\n )\n : undefined;\n if (transitionService && startCoordinator) {\n deps.onFactoryRuntime?.({\n transitionService,\n ...(sourceControlRegistrations.length > 0\n ? {\n prepareBinding: async (input: FactoryBindingPreparationInput) => {\n const sourceControl = await resolveFactorySourceControl({\n sourceControls,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n });\n if (!sourceControl) {\n throw new FactoryDispatchError(\n 'source_control_missing',\n 'Factory project has no linked source-control repository.',\n );\n }\n return prepareFactoryRuleBinding(\n sourceControl,\n startCoordinator,\n deps.domains.projects,\n deps.boardRegistry,\n input,\n deps.domains.intake,\n );\n },\n }\n : {}),\n });\n }\n\n return [\n ...buildFsRoutes({\n root: deps.fsRoot,\n sessionFs: {\n auth: deps.auth,\n sessions: sourceControlSessions,\n filesystem: deps.domains.filesystem,\n },\n }),\n ...new ConfigRoutes({\n auth: deps.auth,\n controller: deps.controller,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n modelDefaults: deps.domains.modelDefaults,\n sourceControlSessions,\n workItems: deps.domains.workItems,\n memorySettings: deps.domains.memorySettings,\n factoryProjects: deps.domains.projects,\n customProviders: deps.domains.customProviders,\n features: { knowledge: deps.knowledgeEnabled },\n deploymentProviders: deps.deploymentModelProviders,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n onCustomProvidersChanged: invalidateCustomProvidersSnapshots,\n }).routes(),\n ...new OAuthRoutes({\n auth: deps.auth,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n }).routes(),\n ...new SkillRoutes({\n auth: deps.auth,\n controllerId: deps.controllerId,\n controller: deps.controller,\n sourceControlStorage: githubStorage,\n ensureSourceControlReady: githubRegistration?.ensureReady,\n }).routes(),\n ...sourceControlSessionRoutes,\n ...(sourceControls.length === 0 ? [] : buildSourceControlSettingsRoutes({ auth: deps.auth, sourceControls })),\n ...providerRoutes,\n ...absentStubs,\n ...slackAbsentStubs,\n ...(deps.intakeReady\n ? new IntakeRoutes({\n auth: deps.auth,\n audit: deps.audit,\n intake: deps.domains.intake,\n projects: deps.domains.projects,\n boardRegistry: deps.boardRegistry,\n // Relocation reads and writes work items, which init fail-soft separately from intake.\n ...(deps.factoryReady ? { workItems: deps.domains.workItems } : {}),\n integrations: (deps.integrations ?? []).flatMap(({ integration }) =>\n integration.intake ? [{ id: integration.id, intake: integration.intake }] : [],\n ),\n }).routes()\n : []),\n ...(deps.factoryReady && deps.knowledgeEnabled\n ? new KnowledgeRoutes({\n auth: deps.auth,\n projects: deps.domains.projects,\n knowledge: async key => deps.controller.getMastra()?.getKnowledge(key),\n defaultKnowledgeKey: deps.knowledgeKey,\n threadTitle: async threadId => {\n const memory = await deps.controller.getMastra()?.getStorage()?.getStore('memory');\n return (await memory?.getThreadById({ threadId }))?.title;\n },\n }).routes()\n : []),\n ...(deps.factoryReady\n ? new WorkItemRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n boardRegistry: deps.boardRegistry,\n comments: deps.domains.comments,\n queueHealth: deps.domains.queueHealth,\n transitionService,\n startCoordinator,\n liveSessions: deps.liveSessions,\n }).routes()\n : []),\n ...(deps.factoryReady\n ? buildAutomationRunRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n configVersion: deps.configVersion,\n })\n : []),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,2BAA2B;CAC/B,eAAe;CACf,kBAAkB;CAClB,gBAAgB;CAChB,eAAe;CACf,eAAe;CACf,iBAAiB;CACjB,cAAc;CACd,aAAa;AACf;AAgEA,SAAS,uBAAuB,EAC9B,aACA,OACA,aACA,UAC+D;CAC/D,IAAI,OAAO,OAAO;CAClB,OAAO,OAAO,KAAI,UAAS;EACzB,IAAI,aAAa,OAAO;GACtB,MAAM,UAAU,MAAM;GACtB,OAAO;IACL,GAAG;IACH,SAAS,OAAO,YAA2C;KACzD,IAAI;MACF,MAAM,YAAY;KACpB,QAAQ;MACN,OAAO,QAAQ,KACb;OAAE,OAAO;OAA2B,SAAS,GAAG,YAAY,GAAG;MAA8B,GAC7F,GACF;KACF;KACA,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC;IACxC;GACF;EACF;EAEA,MAAM,gBAAgB,MAAM;EAC5B,OAAO;GACL,GAAG;GACH,eAAe,OAAO,SAA8C;IAClE,MAAM,UAAU,MAAM,cAAc,IAAI;IACxC,OAAO,OAAO,YAA2C;KACvD,IAAI;MACF,MAAM,YAAY;KACpB,QAAQ;MACN,OAAO,QAAQ,KACb;OAAE,OAAO;OAA2B,SAAS,GAAG,YAAY,GAAG;MAA8B,GAC7F,GACF;KACF;KACA,OAAO,QAAQ,OAAO;IACxB;GACF;EACF;CACF,CAAC;AACH;;;;;;;AAQA,eAAe,kBACb,eACA,OACA,OAAe,MAAM,MAC6B;CAClD,MAAM,MAAM,MAAM,KAAK,SAAS;CAChC,IAAI,CAAC,KAAK,OAAO,KAAA;CAGjB,MAAM,UAAU,MAAM,cAAc,SAAS,eAAe,IAAI,SAAS;CACzE,IACE,CAAC,SAAS,uBACV,QAAQ,UAAU,MAAM,OAAO,S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X,OAAO,KAAK;GACZ,UAAU,KAAK,QAAQ;GACvB,WAAW,KAAK,QAAQ;GACxB,eAAe,KAAK;EACtB,CAAC,IACD,CAAC;CACP;AACF"}
1
+ {"version":3,"file":"surface.js","names":[],"sources":["../../src/routes/surface.ts"],"sourcesContent":["import type { AuthStorage } from '@mastra/code-sdk/auth/storage';\nimport type { MastraCodeState } from '@mastra/code-sdk/schema';\nimport type { AgentController } from '@mastra/core/agent-controller';\nimport type { ApiRoute, IUserProvider } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { FactoryStorage } from '@mastra/core/storage';\nimport type { FactorySandbox } from '@mastra/core/workspace';\n\nimport { boardForWorkItem } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationHooks } from '../integrations/base.js';\nimport { getGithubFeatureDiagnostics } from '../integrations/github/config.js';\nimport type { GithubIntegration } from '../integrations/github/integration.js';\nimport { MaterializeError } from '../integrations/github/sandbox.js';\nimport { FactoryDispatchError } from '../rules/dispatch-errors.js';\nimport type { FactoryBindingPreparationInput } from '../rules/dispatcher.js';\nimport { FactoryStartCoordinator } from '../rules/start-coordinator.js';\nimport { FactoryTransitionService } from '../rules/transition-service.js';\nimport {\n createSourceControlSessionLookup,\n ensureFactorySourceSession,\n FactorySourceSessionResolutionError,\n resolveFactorySourceControl,\n} from '../session/factory-session.js';\nimport type { EnsuredFactorySourceSession } from '../session/factory-session.js';\nimport type { LiveSessions } from '../session/live-sessions.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { StateSigner } from '../state-signing.js';\nimport type { AuditEmitter, AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { ChannelIdentityStorage } from '../storage/domains/channel-identity/base.js';\nimport type { WorkItemCommentsStorage } from '../storage/domains/comments/base.js';\nimport type { CommentsDomain } from '../storage/domains/comments/domain.js';\nimport type { ModelCredentialsStorage } from '../storage/domains/credentials/base.js';\nimport type { CustomProvidersStorage } from '../storage/domains/custom-providers/base.js';\nimport type { FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { IntakeStorage } from '../storage/domains/intake/base.js';\nimport type { IntegrationStorage } from '../storage/domains/integrations/base.js';\nimport type { MemorySettingsStorage } from '../storage/domains/memory-settings/base.js';\nimport type { ModelDefaultsStorage } from '../storage/domains/model-defaults/base.js';\nimport { effectiveModelScope } from '../storage/domains/projects/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { QueueHealthStorage } from '../storage/domains/queue-health/base.js';\nimport {\n SessionOwnershipMismatchError,\n SourceControlConnectionNotFoundError,\n} from '../storage/domains/source-control/base.js';\nimport type { SourceControlStorage, SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\nimport { isAgentActor } from '../storage/domains/work-items/base.js';\nimport type { FactoryDispatchFailureCode, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { workItemBranch, workItemBranchSource, workItemThreadTitle } from '../work-item-branch.js';\nimport { buildAutomationRunRoutes } from './automation-runs.js';\nimport { ConfigRoutes } from './config.js';\nimport { invalidateCustomProvidersSnapshots } from './custom-provider-source.js';\nimport { buildFsRoutes } from './fs.js';\nimport { IntakeRoutes } from './intake.js';\nimport { KnowledgeRoutes } from './knowledge.js';\nimport { OAuthRoutes } from './oauth.js';\nimport type { RouteAuth } from './route.js';\nimport { SkillRoutes } from './skills.js';\nimport { buildSourceControlSessionRoutes } from './source-control-sessions.js';\nimport { buildSourceControlSettingsRoutes } from './source-control-settings.js';\nimport { invalidateTenantCredentialSnapshots } from './tenant-credentials.js';\nimport { WorkItemRoutes } from './work-items.js';\n\nconst MATERIALIZE_FAILURE_CODE = {\n 'git-missing': 'repository_git_missing',\n 'egress-blocked': 'repository_egress_blocked',\n 'clone-failed': 'repository_clone_failed',\n 'pull-failed': 'repository_pull_failed',\n 'push-failed': 'repository_push_failed',\n 'commit-failed': 'repository_commit_failed',\n 'gh-missing': 'repository_cli_missing',\n 'pr-failed': 'repository_pr_failed',\n} satisfies Record<MaterializeError['code'], FactoryDispatchFailureCode>;\nexport interface IntegrationRegistration {\n integration: FactoryIntegration;\n ready: boolean;\n ensureReady: () => Promise<void>;\n}\n\nexport interface FactoryApiRoutesDeps {\n controllerId: string;\n controller: AgentController<MastraCodeState>;\n /** Registry of the sessions this process holds, owned by the host so it can watch them too. */\n liveSessions: LiveSessions;\n /** Request-auth seam threaded from the host (no service locator). */\n auth: RouteAuth;\n /** Optional user directory for resolving persisted owners to display profiles. */\n users?: Pick<IUserProvider, 'getUser' | 'getUsers'>;\n authStorage: AuthStorage;\n audit: AuditEmitter & AuditRecorder;\n fsRoot?: string;\n publicOrigin: string;\n stateSigner?: StateSigner;\n /** Sandbox surface (enablement, provider label, create callback). */\n sandbox?: FactorySandbox;\n /** Push hand-off for environment builds, present when the sandbox can build templates. */\n onRepositoryPush?: IntegrationHooks['onRepositoryPush'];\n /** Root factory storage backend (distributed locks, app-db diagnostics). */\n factoryStorage?: FactoryStorage;\n integrationStorage: IntegrationStorage;\n sourceControlStorage: SourceControlStorage;\n /** App-table domain handles, registered and owned by `MastraFactory.prepare()`. */\n domains: {\n intake: IntakeStorage;\n modelCredentials: ModelCredentialsStorage;\n memorySettings: MemorySettingsStorage;\n customProviders: CustomProvidersStorage;\n filesystem: FilesystemStorage;\n modelDefaults: ModelDefaultsStorage;\n projects: FactoryProjectsStorage;\n queueHealth: QueueHealthStorage;\n workItems: WorkItemsStorage;\n channelIdentity: ChannelIdentityStorage;\n comments: WorkItemCommentsStorage;\n };\n integrations?: IntegrationRegistration[];\n intakeReady: boolean;\n factoryReady: boolean;\n knowledgeEnabled: boolean;\n /** Providers the operator opted in to run on the server process's own credentials. */\n deploymentModelProviders?: ReadonlySet<string>;\n knowledgeKey?: string;\n /** Resolved Factory rule set, threaded from the host (no service locator). */\n configVersion: string;\n /** Boards installed for this Factory instance. */\n boardRegistry: BoardRegistry;\n /** Work-item feed service, handed to integrations that ingest platform messages. */\n feed: CommentsDomain;\n factoryTransitionService?: FactoryTransitionService;\n sessionRetirement?: import('../sandbox/session-retirement.js').SessionRetirementCoordinator;\n onFactoryRuntime?: (runtime: {\n transitionService: FactoryTransitionService;\n startCoordinator: FactoryStartCoordinator;\n prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;\n }) => void;\n}\n\nfunction guardIntegrationRoutes({\n integration,\n ready,\n ensureReady,\n routes,\n}: IntegrationRegistration & { routes: ApiRoute[] }): ApiRoute[] {\n if (ready) return routes;\n return routes.map(route => {\n if ('handler' in route) {\n const handler = route.handler;\n return {\n ...route,\n handler: async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context, async () => {});\n },\n };\n }\n\n const createHandler = route.createHandler;\n return {\n ...route,\n createHandler: async (args: Parameters<typeof createHandler>[0]) => {\n const handler = await createHandler(args);\n return async (context: Parameters<typeof handler>[0]) => {\n try {\n await ensureReady();\n } catch {\n return context.json(\n { error: 'integration_unavailable', message: `${integration.id} integration is unavailable.` },\n 503,\n );\n }\n return handler(context);\n };\n },\n };\n });\n}\n\n/**\n * Resolve the source-control session the work item already holds for this role,\n * when it still resolves to the item's org and factory project. Returns\n * `undefined` when there is no ref or the ref no longer resolves, so the caller\n * falls back to minting one.\n */\nasync function reuseBoundSession(\n sourceControl: SourceControlStorageHandle,\n input: FactoryBindingPreparationInput,\n role: string = input.role,\n): Promise<EnsuredFactorySourceSession | undefined> {\n const ref = input.item.sessions[role];\n if (!ref) return undefined;\n // At least as strict as the coordinator's resolveSourceSession: a ref it\n // would reject must fall through to minting, not hard-fail the run.\n const session = await sourceControl.sessions.getBySessionId(ref.sessionId);\n if (\n !session?.projectRepositoryId ||\n session.orgId !== input.record.orgId ||\n session.factoryProjectId !== input.record.factoryProjectId\n ) {\n return undefined;\n }\n return {\n sessionId: session.sessionId,\n userId: session.userId,\n projectRepositoryId: session.projectRepositoryId,\n branch: session.branch,\n baseBranch: session.baseBranch,\n };\n}\n\n/** Roles whose sessions a later role may continue in, newest stage first. */\nconst INHERITABLE_ROLE_FALLBACK = ['plan', 'triage'];\n\n/**\n * A role running for the first time continues in the card's latest earlier\n * session on the same branch, so a build approved by someone other than the\n * plan's owner keeps the plan's context instead of starting empty. Review is\n * independent by design and never inherits.\n */\nasync function inheritEarlierSession(\n sourceControl: SourceControlStorageHandle,\n input: FactoryBindingPreparationInput,\n board: { roleForPhase(phase: string): string | undefined } | undefined,\n branch: string,\n projectRepositoryId: string,\n): Promise<EnsuredFactorySourceSession | undefined> {\n if (input.role === 'review') return undefined;\n // The card's linked repository can change after an earlier role ran; only\n // continue in a session on the repository a fresh session would use.\n const candidates: string[] = [];\n for (const entry of [...(input.item.stageHistory ?? [])].reverse()) {\n const role = board?.roleForPhase(entry.stage);\n if (role && role !== input.role && role !== 'review' && !candidates.includes(role)) candidates.push(role);\n }\n for (const role of INHERITABLE_ROLE_FALLBACK) {\n if (role !== input.role && !candidates.includes(role)) candidates.push(role);\n }\n for (const role of candidates) {\n const session = await reuseBoundSession(sourceControl, input, role);\n if (session && session.branch === branch && session.projectRepositoryId === projectRepositoryId) {\n return session;\n }\n }\n return undefined;\n}\n\n/**\n * Start a factory run for a rule binding: ensure the source-control session the\n * coordinator requires, then hand it to `prepare` along with the factory's\n * default model. Exported for tests — this is the autonomous entry point with no\n * browser and no interactive user, so nothing else would catch a regression in\n * what it forwards.\n */\nexport async function prepareFactoryRuleBinding(\n sourceControlProvider: SourceControlStorageHandle | Pick<GithubIntegration, 'sourceControlStorage'>,\n coordinator: Pick<FactoryStartCoordinator, 'prepare'>,\n projects: FactoryProjectsStorage,\n boards: BoardRegistry,\n input: FactoryBindingPreparationInput,\n intake?: Pick<IntakeStorage, 'getConfig'>,\n): Promise<void> {\n try {\n const sourceControl =\n 'sourceControlStorage' in sourceControlProvider\n ? sourceControlProvider.sourceControlStorage\n : sourceControlProvider;\n const source = workItemBranchSource(input.item.externalSource);\n const branch = workItemBranch({ id: input.item.id, source, metadata: input.item.metadata });\n // Only leaving a resting phase derives a lane from the role: roles don't own lanes,\n // and the Done close-out running in the triage seat must not drag the card back.\n // Both the current phase and the role's lane come from the installed board; an\n // unknown board or phase yields no destination rather than a guessed one.\n const board = boards.get(boardForWorkItem(input.item));\n const currentStage = input.item.stages.length === 1 ? input.item.stages[0] : undefined;\n const currentKind = currentStage === undefined ? undefined : board?.phaseKind(currentStage);\n const destinationStage =\n currentKind === undefined\n ? undefined\n : currentKind === 'resting'\n ? board?.phaseForRole(input.role)\n : currentStage;\n if (!destinationStage) {\n throw new FactoryDispatchError(\n 'unsupported_provider_item',\n `Factory skill invocation has no destination lane (role \"${input.role}\", stages [${input.item.stages.join(', ')}]).`,\n );\n }\n const connections = await sourceControl.connections.list({\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n });\n if (!connections.some(connection => connection.integrationId === sourceControl.integrationId)) {\n throw new FactoryDispatchError('source_control_missing', 'Factory source-control connection not found.');\n }\n const project = await projects.getById({ id: input.record.factoryProjectId });\n if (!project || project.orgId !== input.record.orgId) {\n throw new FactoryDispatchError(\n 'session_unavailable',\n `Factory model policy is unavailable for project ${input.record.factoryProjectId}.`,\n );\n }\n // A retry may already own a role session. Check it before treating a\n // repository-less card as ambiguous, but never override an explicit signal.\n const boundSession = await reuseBoundSession(sourceControl, input);\n const intakeConfig = await intake?.getConfig({ orgId: input.record.orgId, integrationIds: ['linear'] });\n let repository = await resolveWorkItemRepository({\n sourceControl,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n item: input.item,\n linearRepositoryMap: intakeConfig?.linear?.repositoryByLinearProject,\n });\n if (repository.status === 'ambiguous' && boundSession) {\n const link = await sourceControl.projectRepositories.get({\n orgId: input.record.orgId,\n id: boundSession.projectRepositoryId,\n });\n const linked =\n link && (await sourceControl.repositories.get({ orgId: input.record.orgId, id: link.repositoryId }));\n if (linked && repository.candidates.includes(linked.slug)) {\n repository = { status: 'resolved', slug: linked.slug, projectRepositoryId: link.id };\n }\n }\n if (repository.status !== 'resolved') {\n const detail =\n repository.status === 'ambiguous'\n ? `Choose one of the linked repositories: ${repository.candidates.join(', ')}.`\n : repository.hint;\n throw new FactoryDispatchError('source_repository_ambiguous', detail);\n }\n // Re-preparing a binding (server restart, retired controller session) must\n // land in the role's existing session: minting a replacement would repoint\n // the work item, flip the session's owner to the approver, and orphan the\n // previous sandbox.\n const approver = input.record.approvedBy ?? undefined;\n if (boundSession && boundSession.projectRepositoryId !== repository.projectRepositoryId) {\n throw new FactoryDispatchError(\n 'source_repository_ambiguous',\n `The existing session is bound to a different repository than ${repository.slug}. Choose the correct repository and retry.`,\n );\n }\n // The session is filed under the card's repository: the sandbox holds\n // every environment repository, but the coordinator, the PR tools and the\n // subscriptions follow the session's link, and the card names which one.\n const preparedSession =\n boundSession ??\n (await inheritEarlierSession(sourceControl, input, board, branch, repository.projectRepositoryId)) ??\n (await ensureFactorySourceSession({\n sourceControl,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n projectRepositoryId: repository.projectRepositoryId,\n branch,\n // A person who approved the run is its interactive user: attribute it to\n // them, not the repo connector. An agent's pre-approval names no person.\n attributeToUserId: isAgentActor(approver) ? undefined : approver,\n }).catch(error => {\n if (error instanceof FactorySourceSessionResolutionError && error.reason === 'repository') {\n // The card resolved to a linked repository the sandbox will not check out.\n throw new FactoryDispatchError(\n 'source_repository_missing',\n `Repository ${repository.slug} is linked but not in this Factory's environment. Turn it on under Settings → Environment, then retry.`,\n { cause: error },\n );\n }\n if (!(error instanceof SessionOwnershipMismatchError)) throw error;\n throw new FactoryDispatchError(\n 'session_unavailable',\n `Session ${error.sessionId} on branch ${branch} predates factory ownership and cannot be reused. Delete that session, then retry.`,\n { cause: error },\n );\n }));\n\n const modelScope = effectiveModelScope(project.modelScope, 'run');\n await coordinator.prepare({\n orgId: input.record.orgId,\n userId: preparedSession.userId,\n factoryProjectId: input.record.factoryProjectId,\n sessionId: preparedSession.sessionId,\n modelScope,\n defaultModelId: modelScope === 'factory' ? (project.defaultModelId ?? undefined) : undefined,\n threadTitle: workItemThreadTitle({ source, title: input.item.title, metadata: input.item.metadata }),\n kickoffKey: input.record.id,\n destinationStage,\n workItem: {\n id: input.item.id,\n role: input.role,\n input: {\n externalSource: input.item.externalSource,\n parentWorkItemId: input.item.parentWorkItemId,\n title: input.item.title,\n stages: ['intake'],\n sessions: input.item.sessions,\n metadata: input.item.metadata,\n },\n },\n });\n } catch (error) {\n if (error instanceof FactoryDispatchError) throw error;\n if (error instanceof FactorySourceSessionResolutionError) {\n const code = error.reason === 'connection' ? 'source_control_missing' : 'source_repository_missing';\n throw new FactoryDispatchError(code, error.message, { cause: error });\n }\n if (error instanceof SourceControlConnectionNotFoundError) {\n throw new FactoryDispatchError('source_control_missing', error.message, { cause: error });\n }\n if (error instanceof MaterializeError) {\n throw new FactoryDispatchError(MATERIALIZE_FAILURE_CODE[error.code], error.message, { cause: error });\n }\n throw error;\n }\n}\n\n/**\n * Build the {@link IntegrationContext} handed to an integration when the\n * factory collects its capabilities (routes, workers). One shape everywhere:\n * `assembleFactoryApiRoutes` uses it per registration, and `MastraFactory` uses it\n * when collecting integration workers at finalize.\n */\nexport function buildIntegrationContext(\n deps: Pick<\n FactoryApiRoutesDeps,\n | 'controller'\n | 'publicOrigin'\n | 'auth'\n | 'sandbox'\n | 'users'\n | 'factoryStorage'\n | 'integrationStorage'\n | 'sourceControlStorage'\n | 'integrations'\n > & {\n stateSigner: StateSigner;\n emitAudit?: AuditEmitter['emit'];\n onRepositoryPush?: IntegrationHooks['onRepositoryPush'];\n configVersion: string;\n boardRegistry: BoardRegistry;\n factoryReady: boolean;\n /** Work-item feed service, so a channel integration can ingest platform messages. */\n feed: CommentsDomain;\n domains: Pick<\n FactoryApiRoutesDeps['domains'],\n 'projects' | 'intake' | 'workItems' | 'channelIdentity' | 'memorySettings' | 'modelDefaults'\n >;\n /**\n * Stable id of the registered source-control-owning integration (today:\n * `'github'` when registered). Every call site must derive and pass it so\n * `routes()`, `channels()`, and `workers()` all see the same context shape.\n */\n sourceControlOwnerId?: string;\n },\n integrationId: string,\n): IntegrationContext {\n return {\n auth: deps.auth,\n sandbox: deps.sandbox,\n ...(deps.users ? { users: deps.users } : {}),\n factoryStorage: deps.factoryStorage,\n baseUrl: deps.publicOrigin,\n controller: deps.controller,\n stateSigner: deps.stateSigner,\n storage: {\n generic: deps.integrationStorage.forIntegration(integrationId),\n sourceControl: deps.sourceControlStorage.forIntegration(integrationId),\n ...(deps.sourceControlOwnerId\n ? { sourceControlOwner: deps.sourceControlStorage.forIntegration(deps.sourceControlOwnerId) }\n : {}),\n sourceControls: (deps.integrations ?? [])\n .filter(({ integration }) => integration.versionControl)\n .map(({ integration }) => deps.sourceControlStorage.forIntegration(integration.id)),\n projects: deps.domains.projects,\n intake: deps.domains.intake,\n channelIdentity: deps.domains.channelIdentity,\n memorySettings: deps.domains.memorySettings,\n modelDefaults: deps.domains.modelDefaults,\n },\n ...(deps.factoryReady ? { workItems: deps.domains.workItems, feed: deps.feed } : {}),\n ...(deps.factoryReady\n ? {\n runtime: { configVersion: deps.configVersion, workItems: deps.domains.workItems, boards: deps.boardRegistry },\n }\n : {}),\n ...(deps.emitAudit || deps.onRepositoryPush\n ? {\n hooks: {\n ...(deps.emitAudit ? { emitAudit: deps.emitAudit } : {}),\n ...(deps.onRepositoryPush ? { onRepositoryPush: deps.onRepositoryPush } : {}),\n },\n }\n : {}),\n };\n}\n\n/**\n * Disabled-status stub for the well-known integration ids. The SPA polls\n * `/web/github/status`, `/web/linear/status`, and `/web/jira/status`\n * unconditionally, so when an integration is absent (or not ready) the status\n * contract must still hold. Unknown custom ids get no stub — the SPA doesn't\n * poll them.\n */\nfunction disabledIntegrationStatusRoutes(deps: FactoryApiRoutesDeps, id: string, configured = false): ApiRoute[] {\n if (id === 'github') {\n return [\n registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n installations: [],\n reason: 'missing_config',\n diagnostics: getGithubFeatureDiagnostics({\n github: undefined,\n auth: deps.auth,\n appDbConfigured: deps.factoryStorage !== undefined,\n stateSigner: deps.stateSigner,\n sandbox: deps.sandbox,\n }),\n }),\n }),\n ];\n }\n if (id === 'linear') {\n return [\n registerApiRoute('/web/linear/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n connected: false,\n workspace: null,\n reason: 'missing_config',\n diagnostics: {\n linearAppConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: true,\n },\n }),\n }),\n ];\n }\n if (id === 'jira') {\n return [\n registerApiRoute('/web/jira/status', {\n method: 'GET',\n requiresAuth: false,\n handler: c =>\n c.json({\n enabled: false,\n configured,\n site: null,\n reason: 'missing_config',\n diagnostics: {\n jiraConfigured: configured,\n factoryAuthEnabled: deps.auth.enabled(),\n appDbConfigured: deps.factoryStorage !== undefined,\n },\n }),\n }),\n ];\n }\n return [];\n}\n\n/**\n * Stub for `GET /web/channel-accounts` when NO Slack integration is\n * registered. The SPA's Connections section polls the path unconditionally;\n * without a stub the SPA fallback serves HTML, which the UI can only read as\n * \"old server / unknown\". The machine-readable reason lets it say the truth:\n * the integration isn't registered.\n *\n * Mounted only for ABSENT slack — a registered integration owns the path via\n * its connect routes (or, when the state signer is unstable, gets no routes\n * at all and the UI falls back to the generic copy). Static payload, leaks\n * nothing → no auth needed, same posture as the github/linear stubs.\n */\nfunction absentSlackChannelAccountsRoutes(): ApiRoute[] {\n return [\n registerApiRoute('/web/channel-accounts', {\n method: 'GET',\n requiresAuth: false,\n handler: c => c.json({ accounts: [], canConnect: false, reason: 'not_registered' }),\n }),\n ];\n}\n\n/**\n * Assemble the custom `/web/*` API routes as Mastra `server.apiRoutes`:\n * - fs browser routes (project picker), confined to `fsRoot`\n * - config routes (provider/API-key/default-model/OM management)\n * - every registered integration's `routes()` surface (full set when ready,\n * disabled-status stub otherwise), plus stubs for absent known ids\n */\nexport function assembleFactoryApiRoutes(deps: FactoryApiRoutesDeps): ApiRoute[] {\n const emitAudit: AuditEmitter['emit'] = args => deps.audit.emit(args);\n const registrations = deps.integrations ?? [];\n const githubRegistration = registrations.find(({ integration }) => integration.id === 'github');\n const githubStorage = githubRegistration ? deps.sourceControlStorage.forIntegration('github') : undefined;\n const githubIntegration = githubRegistration?.integration as GithubIntegration | undefined;\n const sourceControlRegistrations = registrations.filter(({ integration }) => integration.versionControl);\n const sourceControlIntegrationIds = [\n ...new Set(['github', ...sourceControlRegistrations.map(({ integration }) => integration.id)]),\n ];\n const sourceControls = sourceControlIntegrationIds.map(id => deps.sourceControlStorage.forIntegration(id));\n const sourceControlSessions = createSourceControlSessionLookup(sourceControls);\n\n const integrationRoutes = registrations.flatMap(registration => {\n const { integration } = registration;\n if (!deps.stateSigner) return disabledIntegrationStatusRoutes(deps, integration.id, true);\n const context = buildIntegrationContext(\n {\n ...deps,\n stateSigner: deps.stateSigner,\n emitAudit,\n ...(githubRegistration ? { sourceControlOwnerId: 'github' } : {}),\n },\n integration.id,\n );\n return guardIntegrationRoutes({ ...registration, routes: integration.routes(context) });\n });\n // Session persistence belongs to the linked source-control provider, not to\n // GitHub. Replace legacy GitHub-owned handlers with one resolver spanning\n // the legacy GitHub partition and every registered source-control partition.\n const sharedSessionRouteKeys = new Set([\n 'GET /web/github/projects/:id/sessions',\n 'POST /web/github/projects/:id/sessions',\n 'GET /web/user-sessions/:sessionId',\n 'DELETE /web/user-sessions/:sessionId',\n 'POST /web/user-sessions/:sessionId/title',\n ]);\n const providerRoutes = integrationRoutes.filter(\n route => !sharedSessionRouteKeys.has(route.method + ' ' + route.path),\n );\n const sourceControlSessionRoutes =\n sourceControls.length === 0\n ? []\n : buildSourceControlSessionRoutes({\n auth: deps.auth,\n sourceControls,\n projects: deps.domains.projects,\n ...(deps.users ? { users: deps.users } : {}),\n controller: deps.controller,\n memorySettings: deps.domains.memorySettings,\n sessionRetirement: deps.sessionRetirement,\n // A local sandbox's destroy keeps the session directory, so recreate\n // couldn't deliver the fresh checkout it promises there.\n sandboxRecreateSupported: deps.sandbox !== undefined && deps.sandbox.provider !== 'local',\n filesystem: deps.domains.filesystem,\n ...(deps.factoryReady ? { workItems: deps.domains.workItems } : {}),\n ...(githubStorage ? { githubRepositories: githubStorage.repositories } : {}),\n });\n // Absent known integrations still get their disabled-status stub.\n const absentStubs = ['github', 'linear', 'jira']\n .filter(id => !registrations.some(({ integration }) => integration.id === id))\n .flatMap(id => disabledIntegrationStatusRoutes(deps, id));\n // Absent slack gets the channel-accounts not-registered stub (registered\n // slack owns the path via its own connect routes).\n const slackAbsentStubs = registrations.some(({ integration }) => integration.id === 'slack')\n ? []\n : absentSlackChannelAccountsRoutes();\n\n const transitionService = deps.factoryReady\n ? (deps.factoryTransitionService ??\n new FactoryTransitionService({\n configVersion: deps.configVersion,\n boards: deps.boardRegistry,\n storage: deps.domains.workItems,\n audit: deps.audit,\n }))\n : undefined;\n const startCoordinator = transitionService\n ? new FactoryStartCoordinator(\n deps.controller,\n deps.domains.workItems,\n transitionService,\n request =>\n resolveFactorySourceControl({\n sourceControls,\n orgId: request.orgId,\n factoryProjectId: request.factoryProjectId,\n sessionId: request.sessionId,\n }),\n deps.domains.intake,\n { projects: deps.domains.projects, modelDefaults: deps.domains.modelDefaults },\n )\n : undefined;\n if (transitionService && startCoordinator) {\n deps.onFactoryRuntime?.({\n transitionService,\n startCoordinator,\n ...(sourceControlRegistrations.length > 0\n ? {\n prepareBinding: async (input: FactoryBindingPreparationInput) => {\n const sourceControl = await resolveFactorySourceControl({\n sourceControls,\n orgId: input.record.orgId,\n factoryProjectId: input.record.factoryProjectId,\n });\n if (!sourceControl) {\n throw new FactoryDispatchError(\n 'source_control_missing',\n 'Factory project has no linked source-control repository.',\n );\n }\n return prepareFactoryRuleBinding(\n sourceControl,\n startCoordinator,\n deps.domains.projects,\n deps.boardRegistry,\n input,\n deps.domains.intake,\n );\n },\n }\n : {}),\n });\n }\n\n return [\n ...buildFsRoutes({\n root: deps.fsRoot,\n sessionFs: {\n auth: deps.auth,\n sessions: sourceControlSessions,\n filesystem: deps.domains.filesystem,\n },\n }),\n ...new ConfigRoutes({\n auth: deps.auth,\n controller: deps.controller,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n modelDefaults: deps.domains.modelDefaults,\n sourceControlSessions,\n sourceControls,\n workItems: deps.domains.workItems,\n memorySettings: deps.domains.memorySettings,\n factoryProjects: deps.domains.projects,\n customProviders: deps.domains.customProviders,\n features: { knowledge: deps.knowledgeEnabled },\n deploymentProviders: deps.deploymentModelProviders,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n onCustomProvidersChanged: invalidateCustomProvidersSnapshots,\n }).routes(),\n ...new OAuthRoutes({\n auth: deps.auth,\n authStorage: deps.authStorage,\n modelCredentials: deps.domains.modelCredentials,\n onCredentialsChanged: invalidateTenantCredentialSnapshots,\n }).routes(),\n ...new SkillRoutes({\n auth: deps.auth,\n controllerId: deps.controllerId,\n controller: deps.controller,\n sourceControlStorage: githubStorage,\n ensureSourceControlReady: githubRegistration?.ensureReady,\n }).routes(),\n ...sourceControlSessionRoutes,\n ...(sourceControls.length === 0 ? [] : buildSourceControlSettingsRoutes({ auth: deps.auth, sourceControls })),\n ...providerRoutes,\n ...absentStubs,\n ...slackAbsentStubs,\n ...(deps.intakeReady\n ? new IntakeRoutes({\n auth: deps.auth,\n audit: deps.audit,\n intake: deps.domains.intake,\n projects: deps.domains.projects,\n boardRegistry: deps.boardRegistry,\n // Relocation reads and writes work items, which init fail-soft separately from intake.\n ...(deps.factoryReady ? { workItems: deps.domains.workItems } : {}),\n integrations: (deps.integrations ?? []).flatMap(({ integration }) =>\n integration.intake ? [{ id: integration.id, intake: integration.intake }] : [],\n ),\n }).routes()\n : []),\n ...(deps.factoryReady && deps.knowledgeEnabled\n ? new KnowledgeRoutes({\n auth: deps.auth,\n projects: deps.domains.projects,\n knowledge: async key => deps.controller.getMastra()?.getKnowledge(key),\n defaultKnowledgeKey: deps.knowledgeKey,\n threadTitle: async threadId => {\n const memory = await deps.controller.getMastra()?.getStorage()?.getStore('memory');\n return (await memory?.getThreadById({ threadId }))?.title;\n },\n }).routes()\n : []),\n ...(deps.factoryReady\n ? new WorkItemRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n boardRegistry: deps.boardRegistry,\n comments: deps.domains.comments,\n queueHealth: deps.domains.queueHealth,\n transitionService,\n startCoordinator,\n liveSessions: deps.liveSessions,\n }).routes()\n : []),\n ...(deps.factoryReady\n ? buildAutomationRunRoutes({\n auth: deps.auth,\n audit: deps.audit,\n projects: deps.domains.projects,\n workItems: deps.domains.workItems,\n configVersion: deps.configVersion,\n })\n : []),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAM,2BAA2B;CAC/B,eAAe;CACf,kBAAkB;CAClB,gBAAgB;CAChB,eAAe;CACf,eAAe;CACf,iBAAiB;CACjB,cAAc;CACd,aAAa;AACf;AAiEA,SAAS,uBAAuB,EAC9B,aACA,OACA,aACA,UAC+D;CAC/D,IAAI,OAAO,OAAO;CAClB,OAAO,OAAO,KAAI,UAAS;EACzB,IAAI,aAAa,OAAO;GACtB,MAAM,UAAU,MAAM;GACtB,OAAO;IACL,GAAG;IACH,SAAS,OAAO,YAA2C;KACzD,IAAI;MACF,MAAM,YAAY;KACpB,QAAQ;MACN,OAAO,QAAQ,KACb;OAAE,OAAO;OAA2B,SAAS,GAAG,YAAY,GAAG;MAA8B,GAC7F,GACF;KACF;KACA,OAAO,QAAQ,SAAS,YAAY,CAAC,CAAC;IACxC;GACF;EACF;EAEA,MAAM,gBAAgB,MAAM;EAC5B,OAAO;GACL,GAAG;GACH,eAAe,OAAO,SAA8C;IAClE,MAAM,UAAU,MAAM,cAAc,IAAI;IACxC,OAAO,OAAO,YAA2C;KACvD,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CAAC;IAC5D,2GAA2G;IAC3G,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC,CAAC;CACvE;AA2CD,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAG7E;AAED,kEAAkE;AAClE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAG7E;AA+ED,qBAAa,cAAe,SAAQ,KAAK,CAAC,kBAAkB,CAAC;;IAoH3D,gEAAgE;IAChE,MAAM,IAAI,QAAQ,EAAE;CAwYrB"}
@@ -3,15 +3,17 @@ import "../boards/index.js";
3
3
  import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, FACTORY_RULE_MATERIALIZATION_KEY, WorkItemRelationError, WorkItemUpdateConflictError } from "../storage/domains/work-items/base.js";
4
4
  import { EXTERNAL_SOURCE_MISSING_KEY } from "../integrations/issue-reconciler.js";
5
5
  import { effectiveModelScope } from "../storage/domains/projects/base.js";
6
+ import { decisionRetryable, overtakenDecisionIds } from "../rules/decision-applicability.js";
6
7
  import { FACTORY_ROUTE_CONTRACTS } from "./contracts.js";
7
8
  import { Route } from "./route.js";
8
9
  import { FactoryStartTransitionError, WorkItemRepositoryError } from "../rules/start-coordinator.js";
10
+ import { createFactoryWorkItem } from "../work-items/create-work-item.js";
11
+ import { factoryDecisionType } from "./attention-providers.js";
12
+ import { buildAttentionRoutes } from "./attention.js";
13
+ import { resolveFactoryProposal, retryFactoryDecision } from "../work-items/decision-actions.js";
9
14
  import { auditRequestOrigin } from "../storage/domains/audit/domain.js";
10
- import { decisionRetryable, overtakenDecisionIds } from "../rules/decision-applicability.js";
11
15
  import { thresholdsOrDefault } from "../storage/domains/queue-health/base.js";
12
16
  import { computeFactoryMetrics, parseMetricsRange } from "../storage/domains/work-items/metrics.js";
13
- import { factoryDecisionType } from "./attention-providers.js";
14
- import { buildAttentionRoutes } from "./attention.js";
15
17
  import { registerApiRoute } from "@mastra/core/server";
16
18
  //#region src/routes/work-items.ts
17
19
  /** The card as clients see it, without the dispatcher's internal bookkeeping. */
@@ -167,7 +169,7 @@ var WorkItemRoutes = class extends Route {
167
169
  });
168
170
  }
169
171
  /** Releasing a parked run and dropping it: same request, opposite outcomes, both audited as consent. */
170
- #proposalRoute({ verb, settle }) {
172
+ #proposalRoute({ verb }) {
171
173
  const { audit, workItems } = this.deps;
172
174
  const contract = verb === "approve" ? FACTORY_ROUTE_CONTRACTS.decisionApprove : FACTORY_ROUTE_CONTRACTS.decisionDismiss;
173
175
  return registerApiRoute(contract.path, {
@@ -183,28 +185,20 @@ var WorkItemRoutes = class extends Route {
183
185
  });
184
186
  if (!parsedPath.success) return c.json({ error: "invalid_decision_id" }, 422);
185
187
  const { decisionId } = parsedPath.data;
186
- await workItems.ensureReady();
187
- const now = /* @__PURE__ */ new Date();
188
- const decision = await settle(resolved.orgId, resolved.factoryProjectId, decisionId, now, resolved.userId);
189
- if (!decision) return c.json({ error: "decision_not_proposed" }, 409);
190
- await audit.emit({
191
- context,
192
- input: {
193
- action: verb === "approve" ? "factory.run.approved" : "factory.run.dismissed",
194
- factoryProjectId: resolved.factoryProjectId,
195
- targets: decision.workItemId ? [{
196
- type: "work_item",
197
- id: decision.workItemId
198
- }] : [{
199
- type: "rule_decision",
200
- id: decision.id
201
- }],
202
- metadata: {
203
- decisionId: decision.id,
204
- effect: factoryDecisionType(decision)
205
- }
206
- }
188
+ const settled = await resolveFactoryProposal({
189
+ workItems,
190
+ audit: (input) => audit.emit({
191
+ context,
192
+ input
193
+ }),
194
+ orgId: resolved.orgId,
195
+ factoryProjectId: resolved.factoryProjectId,
196
+ userId: resolved.userId,
197
+ decisionId,
198
+ action: verb
207
199
  });
200
+ if (!settled.ok) return c.json({ error: settled.code }, 409);
201
+ const { decision } = settled;
208
202
  return c.json({ decision: decisionSummary(this.#boards, decision) });
209
203
  }
210
204
  });
@@ -328,14 +322,8 @@ var WorkItemRoutes = class extends Route {
328
322
  liveSessions,
329
323
  resolveProject: (context) => this.#resolveProject(loose(context))
330
324
  }),
331
- this.#proposalRoute({
332
- verb: "approve",
333
- settle: workItems.approveDeferredDecision.bind(workItems)
334
- }),
335
- this.#proposalRoute({
336
- verb: "dismiss",
337
- settle: workItems.dismissDeferredDecision.bind(workItems)
338
- }),
325
+ this.#proposalRoute({ verb: "approve" }),
326
+ this.#proposalRoute({ verb: "dismiss" }),
339
327
  registerApiRoute(FACTORY_ROUTE_CONTRACTS.decisionRetry.path, {
340
328
  method: FACTORY_ROUTE_CONTRACTS.decisionRetry.method,
341
329
  requiresAuth: false,
@@ -349,12 +337,15 @@ var WorkItemRoutes = class extends Route {
349
337
  });
350
338
  if (!parsedPath.success) return c.json({ error: "invalid_decision_id" }, 422);
351
339
  const { decisionId } = parsedPath.data;
352
- await workItems.ensureReady();
353
- const current = await workItems.getDeferredDecision(resolved.orgId, resolved.factoryProjectId, decisionId);
354
- if (!current || !decisionRetryable(current, false)) return c.json({ error: "decision_not_retryable" }, 409);
355
- if ((await overtakenDecisionIds(workItems, this.#boards, resolved, [current])).size > 0) return c.json({ error: "decision_not_retryable" }, 409);
356
- const decision = await workItems.retryDeferredDecision(resolved.orgId, resolved.factoryProjectId, decisionId, /* @__PURE__ */ new Date());
357
- if (!decision) return c.json({ error: "decision_not_retryable" }, 409);
340
+ const retried = await retryFactoryDecision({
341
+ workItems,
342
+ boards: this.#boards,
343
+ orgId: resolved.orgId,
344
+ factoryProjectId: resolved.factoryProjectId,
345
+ decisionId
346
+ });
347
+ if (!retried.ok) return c.json({ error: retried.code }, 409);
348
+ const { decision } = retried;
358
349
  return c.json({ decision: decisionSummary(this.#boards, decision) });
359
350
  }
360
351
  }),
@@ -368,95 +359,44 @@ var WorkItemRoutes = class extends Route {
368
359
  if (body === void 0) return c.json({ error: "Invalid JSON body" }, 400);
369
360
  const input = parseCreateWorkItem(body);
370
361
  if (!input) return c.json({ error: "invalid_work_item" }, 400);
371
- const boardId = input.board ?? (input.externalSource?.type === "pull-request" ? "review" : "work");
372
- const board = this.#boards.get(boardId);
373
- if (!board) return c.json({
374
- error: "invalid_board",
375
- message: `Board '${boardId}' is not installed.`
376
- }, 422);
377
- const initialStages = input.stages ?? [board.initialPhase];
378
- if (initialStages.length !== 1 || initialStages[0] !== board.initialPhase) return c.json({
379
- error: "governed_transition_required",
380
- message: `New work items must enter through the '${board.initialPhase}' phase of board '${boardId}'.`
381
- }, 409);
382
- await workItems.ensureReady();
383
362
  try {
384
- const result = await workItems.upsert({
363
+ const created = await createFactoryWorkItem({
364
+ workItems,
365
+ boards: this.#boards,
366
+ transitionService,
367
+ audit: (auditInput) => audit.emit({
368
+ context: loose(c),
369
+ input: auditInput
370
+ }),
385
371
  orgId: resolved.orgId,
386
372
  userId: resolved.userId,
387
373
  factoryProjectId: resolved.factoryProjectId,
388
- input: {
389
- ...input,
390
- board: boardId,
391
- stages: initialStages
392
- },
393
- reuseMode: "non-stage"
374
+ input,
375
+ origin: auditRequestOrigin(loose(c))
394
376
  });
395
- let item = result.item;
396
- if (result.created) {
397
- if (!transitionService) {
398
- await workItems.delete({
399
- orgId: resolved.orgId,
400
- id: item.id
401
- });
402
- return c.json({ error: "factory_transitions_unavailable" }, 503);
403
- }
404
- const entered = await transitionService.transition({
405
- orgId: resolved.orgId,
406
- factoryProjectId: resolved.factoryProjectId,
407
- workItemId: item.id,
408
- board: boardId,
409
- stage: board.initialPhase,
410
- expectedRevision: item.revision,
411
- actor: {
412
- type: "human",
413
- id: resolved.userId
414
- },
415
- ...auditRequestOrigin(loose(c)),
416
- ingress: {
417
- type: "human",
418
- identity: `work-item:${item.id}:initial-entry`
419
- },
420
- cause: "work_item_created",
421
- initialEntry: true
422
- });
423
- if (entered.status === "rejected") {
424
- await workItems.delete({
425
- orgId: resolved.orgId,
426
- id: item.id
427
- });
377
+ switch (created.status) {
378
+ case "refused":
379
+ if (created.code === "factory_transitions_unavailable") return c.json({ error: created.code }, 503);
428
380
  return c.json({
429
- status: "rejected",
430
- code: entered.code,
431
- reason: entered.reason
432
- }, 422);
381
+ error: created.code,
382
+ message: created.message
383
+ }, created.code === "invalid_board" ? 422 : 409);
384
+ case "rejected": return c.json({
385
+ status: "rejected",
386
+ code: created.code,
387
+ reason: created.reason
388
+ }, 422);
389
+ case "reused": {
390
+ const { stages: _stages, sessions: _sessions, ...boundedPatch } = input;
391
+ await this.#auditWorkItemPatch({
392
+ context: loose(c),
393
+ item: created.item,
394
+ patch: boundedPatch
395
+ });
396
+ return c.json({ workItem: toWireWorkItem(created.item) });
433
397
  }
434
- item = await workItems.getForProject(resolved.orgId, resolved.factoryProjectId, item.id) ?? item;
435
- await audit.emit({
436
- context: loose(c),
437
- input: {
438
- action: "factory.work_item.created",
439
- factoryProjectId: resolved.factoryProjectId,
440
- targets: [{
441
- type: "work_item",
442
- id: item.id,
443
- name: item.title
444
- }],
445
- metadata: {
446
- externalSource: item.externalSource,
447
- stages: item.stages
448
- }
449
- }
450
- });
451
- } else {
452
- const { stages: _stages, sessions: _sessions, ...boundedPatch } = input;
453
- await this.#auditWorkItemPatch({
454
- context: loose(c),
455
- item,
456
- patch: boundedPatch
457
- });
398
+ case "created": return c.json({ workItem: toWireWorkItem(created.item) });
458
399
  }
459
- return c.json({ workItem: toWireWorkItem(item) });
460
400
  } catch (error) {
461
401
  if (error instanceof WorkItemRelationError) return c.json({
462
402
  error: error.code,