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

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 (335) hide show
  1. package/README.md +210 -42
  2. package/dist/boards/board-events.d.ts +34 -0
  3. package/dist/boards/board-events.d.ts.map +1 -0
  4. package/dist/boards/board-events.js +50 -0
  5. package/dist/boards/board-events.js.map +1 -0
  6. package/dist/boards/board-writes.d.ts +86 -0
  7. package/dist/boards/board-writes.d.ts.map +1 -0
  8. package/dist/boards/board-writes.js +252 -0
  9. package/dist/boards/board-writes.js.map +1 -0
  10. package/dist/boards/define-board.d.ts +16 -5
  11. package/dist/boards/define-board.d.ts.map +1 -1
  12. package/dist/boards/define-board.js +30 -8
  13. package/dist/boards/define-board.js.map +1 -1
  14. package/dist/boards/intake-routing.d.ts +30 -6
  15. package/dist/boards/intake-routing.d.ts.map +1 -1
  16. package/dist/boards/intake-routing.js +43 -5
  17. package/dist/boards/intake-routing.js.map +1 -1
  18. package/dist/boards/legacy-plan-role.d.ts.map +1 -1
  19. package/dist/boards/legacy-plan-role.js +8 -4
  20. package/dist/boards/legacy-plan-role.js.map +1 -1
  21. package/dist/boards/phase-automation.d.ts.map +1 -1
  22. package/dist/boards/phase-automation.js +7 -2
  23. package/dist/boards/phase-automation.js.map +1 -1
  24. package/dist/boards/project-boards.d.ts +18 -7
  25. package/dist/boards/project-boards.d.ts.map +1 -1
  26. package/dist/boards/project-boards.js +78 -14
  27. package/dist/boards/project-boards.js.map +1 -1
  28. package/dist/boards/stored-board.d.ts +59 -1
  29. package/dist/boards/stored-board.d.ts.map +1 -1
  30. package/dist/boards/stored-board.js +219 -7
  31. package/dist/boards/stored-board.js.map +1 -1
  32. package/dist/factory.d.ts +63 -9
  33. package/dist/factory.d.ts.map +1 -1
  34. package/dist/factory.js +187 -22
  35. package/dist/factory.js.map +1 -1
  36. package/dist/index.d.ts +3 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +4 -3
  39. package/dist/integrations/base.d.ts +6 -0
  40. package/dist/integrations/base.d.ts.map +1 -1
  41. package/dist/integrations/github/acceptance-labels.d.ts +4 -0
  42. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
  43. package/dist/integrations/github/acceptance-labels.js +1 -1
  44. package/dist/integrations/github/acceptance-labels.js.map +1 -1
  45. package/dist/integrations/github/default-rules.d.ts +2 -9
  46. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  47. package/dist/integrations/github/default-rules.js +7 -6
  48. package/dist/integrations/github/default-rules.js.map +1 -1
  49. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  50. package/dist/integrations/github/issue-reconciler.js +17 -1
  51. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  52. package/dist/integrations/github/review-status-comment.d.ts +61 -0
  53. package/dist/integrations/github/review-status-comment.d.ts.map +1 -0
  54. package/dist/integrations/github/review-status-comment.js +217 -0
  55. package/dist/integrations/github/review-status-comment.js.map +1 -0
  56. package/dist/integrations/github/review-status-reporter.d.ts +42 -0
  57. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -0
  58. package/dist/integrations/github/review-status-reporter.js +100 -0
  59. package/dist/integrations/github/review-status-reporter.js.map +1 -0
  60. package/dist/integrations/github/review-status.d.ts +28 -0
  61. package/dist/integrations/github/review-status.d.ts.map +1 -0
  62. package/dist/integrations/github/review-status.js +95 -0
  63. package/dist/integrations/github/review-status.js.map +1 -0
  64. package/dist/integrations/github/routes.d.ts.map +1 -1
  65. package/dist/integrations/github/routes.js +2 -5
  66. package/dist/integrations/github/routes.js.map +1 -1
  67. package/dist/integrations/github/rules.d.ts +13 -1
  68. package/dist/integrations/github/rules.d.ts.map +1 -1
  69. package/dist/integrations/github/rules.js +77 -6
  70. package/dist/integrations/github/rules.js.map +1 -1
  71. package/dist/integrations/gitlab/default-rules.d.ts +24 -9
  72. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  73. package/dist/integrations/gitlab/default-rules.js +4 -4
  74. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  75. package/dist/integrations/gitlab/merge-request-reconciler.js +1 -1
  76. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  77. package/dist/integrations/gitlab/routes.js +1 -3
  78. package/dist/integrations/gitlab/routes.js.map +1 -1
  79. package/dist/integrations/gitlab/rules.d.ts +16 -0
  80. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  81. package/dist/integrations/gitlab/rules.js +69 -4
  82. package/dist/integrations/gitlab/rules.js.map +1 -1
  83. package/dist/integrations/incidentio/default-rules.d.ts +1 -9
  84. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
  85. package/dist/integrations/incidentio/default-rules.js +3 -4
  86. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  87. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  88. package/dist/integrations/incidentio/routes.js +1 -4
  89. package/dist/integrations/incidentio/routes.js.map +1 -1
  90. package/dist/integrations/incidentio/rules.d.ts +7 -0
  91. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  92. package/dist/integrations/incidentio/rules.js +35 -3
  93. package/dist/integrations/incidentio/rules.js.map +1 -1
  94. package/dist/integrations/jira/default-rules.d.ts +1 -9
  95. package/dist/integrations/jira/default-rules.d.ts.map +1 -1
  96. package/dist/integrations/jira/default-rules.js +3 -4
  97. package/dist/integrations/jira/default-rules.js.map +1 -1
  98. package/dist/integrations/jira/routes.d.ts.map +1 -1
  99. package/dist/integrations/jira/routes.js +1 -4
  100. package/dist/integrations/jira/routes.js.map +1 -1
  101. package/dist/integrations/jira/rules.d.ts +7 -0
  102. package/dist/integrations/jira/rules.d.ts.map +1 -1
  103. package/dist/integrations/jira/rules.js +35 -3
  104. package/dist/integrations/jira/rules.js.map +1 -1
  105. package/dist/integrations/linear/default-rules.d.ts +1 -9
  106. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  107. package/dist/integrations/linear/default-rules.js +3 -4
  108. package/dist/integrations/linear/default-rules.js.map +1 -1
  109. package/dist/integrations/linear/routes.d.ts.map +1 -1
  110. package/dist/integrations/linear/routes.js +1 -4
  111. package/dist/integrations/linear/routes.js.map +1 -1
  112. package/dist/integrations/linear/rules.d.ts +7 -0
  113. package/dist/integrations/linear/rules.d.ts.map +1 -1
  114. package/dist/integrations/linear/rules.js +35 -3
  115. package/dist/integrations/linear/rules.js.map +1 -1
  116. package/dist/integrations/platform/connect/routes.d.ts +7 -1
  117. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  118. package/dist/integrations/platform/connect/routes.js +42 -5
  119. package/dist/integrations/platform/connect/routes.js.map +1 -1
  120. package/dist/integrations/platform/connect/session-tools.d.ts +7 -0
  121. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -0
  122. package/dist/integrations/platform/connect/session-tools.js +30 -0
  123. package/dist/integrations/platform/connect/session-tools.js.map +1 -0
  124. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  125. package/dist/integrations/platform/github/integration.js +1 -3
  126. package/dist/integrations/platform/github/integration.js.map +1 -1
  127. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  128. package/dist/integrations/platform/jira/routes.js +1 -4
  129. package/dist/integrations/platform/jira/routes.js.map +1 -1
  130. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  131. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  132. package/dist/integrations/platform/linear/event-worker.js +9 -0
  133. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  134. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  135. package/dist/integrations/platform/linear/integration.js +1 -3
  136. package/dist/integrations/platform/linear/integration.js.map +1 -1
  137. package/dist/integrations/slack/channel-reply-processor.d.ts +2 -0
  138. package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
  139. package/dist/integrations/slack/channel-reply-processor.js +6 -1
  140. package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
  141. package/dist/integrations/slack/connect-route.d.ts.map +1 -1
  142. package/dist/integrations/slack/connect-route.js +1 -1
  143. package/dist/integrations/slack/connect-route.js.map +1 -1
  144. package/dist/integrations/slack/integration.d.ts.map +1 -1
  145. package/dist/integrations/slack/integration.js +2 -0
  146. package/dist/integrations/slack/integration.js.map +1 -1
  147. package/dist/integrations/slack/slack.d.ts +12 -10
  148. package/dist/integrations/slack/slack.d.ts.map +1 -1
  149. package/dist/integrations/slack/slack.js +110 -43
  150. package/dist/integrations/slack/slack.js.map +1 -1
  151. package/dist/integrations/slack/voice-clips.d.ts +32 -0
  152. package/dist/integrations/slack/voice-clips.d.ts.map +1 -0
  153. package/dist/integrations/slack/voice-clips.js +201 -0
  154. package/dist/integrations/slack/voice-clips.js.map +1 -0
  155. package/dist/integrations/workos/integration.d.ts.map +1 -1
  156. package/dist/integrations/workos/integration.js +1 -3
  157. package/dist/integrations/workos/integration.js.map +1 -1
  158. package/dist/mcp/routes.js +1 -1
  159. package/dist/packages/_internals/workspace/dist/index.js +1 -1
  160. package/dist/routes/attention-activity.js +1 -1
  161. package/dist/routes/attention-providers.js +1 -1
  162. package/dist/routes/automation-runs.d.ts.map +1 -1
  163. package/dist/routes/automation-runs.js +1 -4
  164. package/dist/routes/automation-runs.js.map +1 -1
  165. package/dist/routes/boards.d.ts +8 -6
  166. package/dist/routes/boards.d.ts.map +1 -1
  167. package/dist/routes/boards.js +73 -143
  168. package/dist/routes/boards.js.map +1 -1
  169. package/dist/routes/config.d.ts.map +1 -1
  170. package/dist/routes/config.js +3 -8
  171. package/dist/routes/config.js.map +1 -1
  172. package/dist/routes/contracts.d.ts +132 -0
  173. package/dist/routes/contracts.d.ts.map +1 -1
  174. package/dist/routes/contracts.js +77 -29
  175. package/dist/routes/contracts.js.map +1 -1
  176. package/dist/routes/fs.d.ts.map +1 -1
  177. package/dist/routes/fs.js +1 -4
  178. package/dist/routes/fs.js.map +1 -1
  179. package/dist/routes/intake-routes.d.ts.map +1 -1
  180. package/dist/routes/intake-routes.js +19 -12
  181. package/dist/routes/intake-routes.js.map +1 -1
  182. package/dist/routes/intake.d.ts.map +1 -1
  183. package/dist/routes/intake.js +3 -5
  184. package/dist/routes/intake.js.map +1 -1
  185. package/dist/routes/knowledge.d.ts.map +1 -1
  186. package/dist/routes/knowledge.js +1 -4
  187. package/dist/routes/knowledge.js.map +1 -1
  188. package/dist/routes/oauth.d.ts.map +1 -1
  189. package/dist/routes/oauth.js +1 -4
  190. package/dist/routes/oauth.js.map +1 -1
  191. package/dist/routes/projects.d.ts +3 -0
  192. package/dist/routes/projects.d.ts.map +1 -1
  193. package/dist/routes/projects.js +7 -4
  194. package/dist/routes/projects.js.map +1 -1
  195. package/dist/routes/provider-credentials.d.ts.map +1 -1
  196. package/dist/routes/provider-credentials.js +6 -0
  197. package/dist/routes/provider-credentials.js.map +1 -1
  198. package/dist/routes/route.d.ts +2 -0
  199. package/dist/routes/route.d.ts.map +1 -1
  200. package/dist/routes/route.js +5 -1
  201. package/dist/routes/route.js.map +1 -1
  202. package/dist/routes/skills.d.ts.map +1 -1
  203. package/dist/routes/skills.js +1 -4
  204. package/dist/routes/skills.js.map +1 -1
  205. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  206. package/dist/routes/source-control-sessions.js +1 -3
  207. package/dist/routes/source-control-sessions.js.map +1 -1
  208. package/dist/routes/source-control-settings.d.ts.map +1 -1
  209. package/dist/routes/source-control-settings.js +3 -2
  210. package/dist/routes/source-control-settings.js.map +1 -1
  211. package/dist/routes/surface.d.ts +3 -1
  212. package/dist/routes/surface.d.ts.map +1 -1
  213. package/dist/routes/surface.js +11 -1
  214. package/dist/routes/surface.js.map +1 -1
  215. package/dist/routes/voice.d.ts +48 -0
  216. package/dist/routes/voice.d.ts.map +1 -0
  217. package/dist/routes/voice.js +248 -0
  218. package/dist/routes/voice.js.map +1 -0
  219. package/dist/routes/work-items.d.ts.map +1 -1
  220. package/dist/routes/work-items.js +1 -4
  221. package/dist/routes/work-items.js.map +1 -1
  222. package/dist/rules/decision-applicability.js +1 -1
  223. package/dist/rules/dispatcher.d.ts +28 -0
  224. package/dist/rules/dispatcher.d.ts.map +1 -1
  225. package/dist/rules/dispatcher.js +391 -93
  226. package/dist/rules/dispatcher.js.map +1 -1
  227. package/dist/rules/event-rules.d.ts +40 -1
  228. package/dist/rules/event-rules.d.ts.map +1 -1
  229. package/dist/rules/event-rules.js +59 -1
  230. package/dist/rules/event-rules.js.map +1 -1
  231. package/dist/rules/processor.js +1 -1
  232. package/dist/rules/processor.js.map +1 -1
  233. package/dist/rules/transition-service.d.ts +9 -0
  234. package/dist/rules/transition-service.d.ts.map +1 -1
  235. package/dist/rules/transition-service.js +4 -2
  236. package/dist/rules/transition-service.js.map +1 -1
  237. package/dist/rules/types.d.ts +54 -3
  238. package/dist/rules/types.d.ts.map +1 -1
  239. package/dist/rules/types.js +2 -0
  240. package/dist/rules/types.js.map +1 -1
  241. package/dist/rules/validation.d.ts.map +1 -1
  242. package/dist/rules/validation.js +57 -2
  243. package/dist/rules/validation.js.map +1 -1
  244. package/dist/session/credential-policy.d.ts +2 -2
  245. package/dist/session/credential-policy.d.ts.map +1 -1
  246. package/dist/session/credential-policy.js +3 -3
  247. package/dist/session/credential-policy.js.map +1 -1
  248. package/dist/session/default-model-hydration.d.ts +2 -2
  249. package/dist/session/default-model-hydration.d.ts.map +1 -1
  250. package/dist/session/default-model-hydration.js +4 -4
  251. package/dist/session/default-model-hydration.js.map +1 -1
  252. package/dist/session/session-threads.d.ts +8 -0
  253. package/dist/session/session-threads.d.ts.map +1 -1
  254. package/dist/session/session-threads.js +11 -1
  255. package/dist/session/session-threads.js.map +1 -1
  256. package/dist/skills/catalog.js +1 -1
  257. package/dist/storage/domains/audit/actions.d.ts +1 -1
  258. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  259. package/dist/storage/domains/audit/actions.js +2 -1
  260. package/dist/storage/domains/audit/actions.js.map +1 -1
  261. package/dist/storage/domains/audit/domain.d.ts.map +1 -1
  262. package/dist/storage/domains/audit/domain.js +1 -3
  263. package/dist/storage/domains/audit/domain.js.map +1 -1
  264. package/dist/storage/domains/boards/base.d.ts +32 -1
  265. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  266. package/dist/storage/domains/boards/base.js +155 -8
  267. package/dist/storage/domains/boards/base.js.map +1 -1
  268. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  269. package/dist/storage/domains/boards/schemas.js +13 -1
  270. package/dist/storage/domains/boards/schemas.js.map +1 -1
  271. package/dist/storage/domains/comments/routes.d.ts.map +1 -1
  272. package/dist/storage/domains/comments/routes.js +1 -3
  273. package/dist/storage/domains/comments/routes.js.map +1 -1
  274. package/dist/storage/domains/memory-settings/base.d.ts +0 -8
  275. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -1
  276. package/dist/storage/domains/memory-settings/base.js +1 -11
  277. package/dist/storage/domains/memory-settings/base.js.map +1 -1
  278. package/dist/storage/domains/projects/base.d.ts +6 -0
  279. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  280. package/dist/storage/domains/projects/base.js +9 -1
  281. package/dist/storage/domains/projects/base.js.map +1 -1
  282. package/dist/storage/domains/voice-settings/base.d.ts +31 -0
  283. package/dist/storage/domains/voice-settings/base.d.ts.map +1 -0
  284. package/dist/storage/domains/voice-settings/base.js +81 -0
  285. package/dist/storage/domains/voice-settings/base.js.map +1 -0
  286. package/dist/storage/domains/work-items/base.d.ts +31 -2
  287. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  288. package/dist/storage/domains/work-items/base.js +197 -44
  289. package/dist/storage/domains/work-items/base.js.map +1 -1
  290. package/dist/storage/domains/work-items/cards.d.ts +6 -1
  291. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  292. package/dist/storage/domains/work-items/cards.js +54 -4
  293. package/dist/storage/domains/work-items/cards.js.map +1 -1
  294. package/dist/storage/domains/work-items/work-item-schema.d.ts +2 -0
  295. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  296. package/dist/storage/domains/work-items/work-item-schema.js +24 -1
  297. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  298. package/dist/timing.d.ts +1 -0
  299. package/dist/timing.d.ts.map +1 -1
  300. package/dist/timing.js +1 -1
  301. package/dist/timing.js.map +1 -1
  302. package/dist/tools/read-tools.d.ts +2 -2
  303. package/dist/tools/read-tools.d.ts.map +1 -1
  304. package/dist/tools/read-tools.js +7 -6
  305. package/dist/tools/read-tools.js.map +1 -1
  306. package/dist/tools/session-tools.d.ts +1 -1
  307. package/dist/tools/session-tools.d.ts.map +1 -1
  308. package/dist/tools/session-tools.js.map +1 -1
  309. package/dist/tools/sessions-state-processor.d.ts +1 -1
  310. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  311. package/dist/tools/sessions-state-processor.js +9 -2
  312. package/dist/tools/sessions-state-processor.js.map +1 -1
  313. package/dist/tools/work-item-tools.js +2 -2
  314. package/dist/voice/rate-limit.d.ts +13 -0
  315. package/dist/voice/rate-limit.d.ts.map +1 -0
  316. package/dist/voice/rate-limit.js +36 -0
  317. package/dist/voice/rate-limit.js.map +1 -0
  318. package/dist/voice/realtime.d.ts +13 -0
  319. package/dist/voice/realtime.d.ts.map +1 -0
  320. package/dist/voice/realtime.js +56 -0
  321. package/dist/voice/realtime.js.map +1 -0
  322. package/dist/voice/transcription.d.ts +51 -0
  323. package/dist/voice/transcription.d.ts.map +1 -0
  324. package/dist/voice/transcription.js +112 -0
  325. package/dist/voice/transcription.js.map +1 -0
  326. package/dist/work-items/split-backfill.d.ts +13 -0
  327. package/dist/work-items/split-backfill.d.ts.map +1 -0
  328. package/dist/work-items/split-backfill.js +32 -0
  329. package/dist/work-items/split-backfill.js.map +1 -0
  330. package/dist/work-items/split-migration.d.ts +39 -2
  331. package/dist/work-items/split-migration.d.ts.map +1 -1
  332. package/dist/work-items/split-migration.js +170 -62
  333. package/dist/work-items/split-migration.js.map +1 -1
  334. package/dist/workspace.js +2 -2
  335. package/package.json +12 -11
@@ -1 +1 @@
1
- {"version":3,"file":"define-board.js","names":[],"sources":["../../src/boards/define-board.ts"],"sourcesContent":["import { CODE_AGENT_ID } from '@mastra/code-sdk/constants';\nimport { cardRuleGroupSchema, evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { RuleFacts, RuleGroup } from '../rules/rule-group.js';\nimport {\n FACTORY_GITHUB_EVENTS,\n FACTORY_RULE_SOURCES,\n FACTORY_GITLAB_EVENTS,\n FACTORY_INCIDENTIO_EVENTS,\n FACTORY_JIRA_EVENTS,\n FACTORY_LINEAR_EVENTS,\n} from '../rules/types.js';\nimport type {\n FactoryGithubEventName,\n FactoryGithubRuleContext,\n FactoryGitLabEventName,\n FactoryGitLabRuleContext,\n FactoryIncidentioEventName,\n FactoryIncidentioRuleContext,\n FactoryJiraEventName,\n FactoryJiraRuleContext,\n FactoryLinearEventName,\n FactoryLinearRuleContext,\n FactoryRuleHandler,\n FactoryRuleSource,\n FactoryStageRuleContext,\n FactoryToolResultRuleContext,\n} from '../rules/types.js';\nimport {\n IDENTIFIER_RE,\n isBoardIdentifier,\n MAX_ROLE_LENGTH,\n MAX_SKILL_NAME_LENGTH,\n MAX_TOOL_NAME_LENGTH,\n SKILL_NAME_RE,\n} from '../rules/validation.js';\nimport { addInstructions, startSkill } from './phase-runner.js';\nimport type { BoardTransitionPolicy } from './transition-policy.js';\n\ntype BoardPhaseHandlers = Partial<Record<FactoryRuleSource, FactoryRuleHandler<FactoryStageRuleContext>>>;\ntype ReadonlyBoardPhaseHandlers = Readonly<BoardPhaseHandlers>;\n\n/** Runs when an agent seated on this board completes the named tool. */\nexport type BoardToolResultRuleHandler = FactoryRuleHandler<FactoryToolResultRuleContext>;\nexport type BoardToolRule = { readonly onResult: BoardToolResultRuleHandler };\nexport type BoardToolRules = Readonly<Record<string, BoardToolRule>>;\n\n/**\n * A board's handler for one integration event. `null` switches the integration default off\n * for cards on this board only.\n */\ntype BoardEventHandlerMap<EventName extends string, Context> = Readonly<\n Partial<Record<EventName, FactoryRuleHandler<Context> | null>>\n>;\n\n/**\n * How cards on this board react to integration events, keyed by integration then event.\n * Consulted for events bound to a card on this board, after any handler the deployment set\n * explicitly on the integration and before the integration default.\n */\nexport interface BoardEventRules {\n readonly github?: BoardEventHandlerMap<FactoryGithubEventName, FactoryGithubRuleContext>;\n readonly gitlab?: BoardEventHandlerMap<FactoryGitLabEventName, FactoryGitLabRuleContext>;\n readonly linear?: BoardEventHandlerMap<FactoryLinearEventName, FactoryLinearRuleContext>;\n readonly jira?: BoardEventHandlerMap<FactoryJiraEventName, FactoryJiraRuleContext>;\n readonly incidentio?: BoardEventHandlerMap<FactoryIncidentioEventName, FactoryIncidentioRuleContext>;\n}\nexport type BoardEventIntegration = keyof BoardEventRules;\n\nconst BOARD_EVENT_NAMES: Readonly<Record<BoardEventIntegration, readonly string[]>> = {\n github: FACTORY_GITHUB_EVENTS,\n gitlab: FACTORY_GITLAB_EVENTS,\n linear: FACTORY_LINEAR_EVENTS,\n jira: FACTORY_JIRA_EVENTS,\n incidentio: FACTORY_INCIDENTIO_EVENTS,\n};\n\ntype ReadonlyFactoryBoardRules = Readonly<\n Record<\n string,\n Readonly<\n Partial<\n Record<\n FactoryRuleSource,\n Readonly<{\n onEnter?: FactoryRuleHandler<FactoryStageRuleContext>;\n onExit?: FactoryRuleHandler<FactoryStageRuleContext>;\n }>\n >\n >\n >\n >\n>;\n\n/**\n * What a phase means to the runtime.\n * - `resting`: nobody is seated; a card waits for a person or an event.\n * - `working`: an agent in the phase's context carries the card; a person's move in arms autonomy.\n * - `terminal`: the card is finished; sessions stop and held resources are released.\n */\nexport type BoardPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** The agent Factory runs every phase with. */\nexport const FACTORY_AGENT_ID = CODE_AGENT_ID;\n\n/** The session context a working phase runs in when it names none. */\nexport const DEFAULT_PHASE_CONTEXT = 'work';\n\n/** Who runs a working phase, and with what. */\nexport interface BoardPhaseRunner {\n /** Must be `code-agent`, the agent Factory runs; omitted means that agent. */\n readonly agentId?: string;\n /** Skill started when a card enters the phase from a source with no `onEnter` handler. */\n readonly skill?: string;\n /**\n * The session the phase runs in. Phases naming the same context share one session per card;\n * a different context gets its own. Defaults to `work`.\n */\n readonly context?: string;\n /** Appended to every run the phase starts. */\n readonly instructions?: string;\n}\n\n/**\n * The tool whose successful call ends a working phase. The agent then moves the card itself with\n * `factory_transition_work_item`, to one of the phase's `nextPhases`.\n */\nexport interface BoardPhaseExitTool {\n readonly id: string;\n /**\n * Answer the approval the tool waits for without a person. Factory sessions run other tools\n * without asking, so today this applies to `submit_plan`. Defaults to false.\n */\n readonly autoApprove?: boolean;\n /** With `autoApprove`, only cards this matches are approved without a person. */\n readonly autoApproveWhen?: RuleGroup;\n}\n\ntype BoardPhaseBase<PhaseId extends string> = {\n readonly name?: string;\n /** @deprecated Use `name`. */\n readonly title?: string;\n readonly description?: string;\n /** Phases a card may move to from here. */\n readonly nextPhases?: readonly PhaseId[];\n /** @deprecated List the phase in `nextPhases`. */\n readonly next?: PhaseId;\n /** Named moves rules can choose by outcome; each target is also an allowed next phase. */\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n readonly onEnter?: ReadonlyBoardPhaseHandlers;\n readonly onExit?: ReadonlyBoardPhaseHandlers;\n};\n\ntype WorkingPhaseFields = {\n readonly runner?: BoardPhaseRunner;\n /** @deprecated Use `runner.context`. */\n readonly role?: string;\n /** Runs start without anyone approving them, even with the project's auto-run off. */\n readonly autoStart?: boolean;\n /** With `autoStart`, only cards this matches start on their own. */\n readonly autoStartWhen?: RuleGroup;\n /** A bare tool name is shorthand for `{ id }`, with nothing approved on a person's behalf. */\n readonly exitTool?: string | BoardPhaseExitTool;\n};\n\ntype NonWorkingPhaseFields = {\n readonly runner?: never;\n readonly role?: never;\n readonly autoStart?: never;\n readonly autoStartWhen?: never;\n readonly exitTool?: never;\n};\n\n/** A phase as a board declares it. */\nexport type BoardPhaseDefinition<PhaseId extends string> =\n | (BoardPhaseBase<PhaseId> & NonWorkingPhaseFields & { readonly kind: 'resting' })\n | (BoardPhaseBase<PhaseId> & WorkingPhaseFields & { readonly kind: 'working' })\n | (BoardPhaseBase<PhaseId> & NonWorkingPhaseFields & { readonly kind: 'terminal' });\n\ntype ResolvedPhaseBase<PhaseId extends string> = {\n readonly name: string;\n /** @deprecated Use `name`; kept equal to it for code written against older Factory versions. */\n readonly title: string;\n readonly description?: string;\n /** Every phase a card may move to from here, including outcome targets. */\n readonly nextPhases: readonly PhaseId[];\n /** @deprecated Use `nextPhases`; set when the phase declared `next`. */\n readonly next?: PhaseId;\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n readonly onEnter?: ReadonlyBoardPhaseHandlers;\n readonly onExit?: ReadonlyBoardPhaseHandlers;\n};\n\n/**\n * A phase as the board resolved it: deprecated fields are replaced by their new names, so\n * only the new structure leaves `defineBoard()`, and a resolved phase can be declared again.\n */\nexport type BoardPhase<PhaseId extends string> =\n | (ResolvedPhaseBase<PhaseId> & { readonly kind: 'resting' })\n | (ResolvedPhaseBase<PhaseId> & {\n readonly kind: 'working';\n readonly runner: Readonly<BoardPhaseRunner & { agentId: string; context: string }>;\n /** @deprecated Use `runner.context`; kept equal to it. */\n readonly role: string;\n readonly autoStart?: boolean;\n readonly autoStartWhen?: RuleGroup;\n readonly exitTool?: Readonly<{ id: string; autoApprove: boolean; autoApproveWhen?: RuleGroup }>;\n })\n | (ResolvedPhaseBase<PhaseId> & { readonly kind: 'terminal' });\n\ntype ResolvedRunner = Extract<BoardPhase<string>, { kind: 'working' }>['runner'];\ntype ResolvedExitTool = Extract<BoardPhase<string>, { kind: 'working' }>['exitTool'];\n\nexport interface BoardTransition<PhaseId extends string> {\n readonly outcome: string | null;\n readonly to: PhaseId;\n}\n\n/**\n * Terminal phases a card moves to when its tracked source (issue or follow-up) closes.\n * `completed` is used when the source was completed, `canceled` when it was canceled or not planned.\n */\nexport type BoardSourceClosed<PhaseId extends string> = Readonly<{ completed: PhaseId; canceled: PhaseId }>;\n\nexport interface BoardDefinition<BoardId extends string, PhaseId extends string> {\n readonly id: BoardId;\n readonly name: string;\n /** @deprecated Use `name`; kept equal to it for code written against older Factory versions. */\n readonly title: string;\n readonly description?: string;\n readonly initialPhase: PhaseId;\n readonly phases: Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\n readonly transitions: Readonly<Record<PhaseId, readonly BoardTransition<PhaseId>[]>>;\n readonly rules: ReadonlyFactoryBoardRules;\n /** Tool-result rules keyed by tool name; empty when the board declares none. */\n readonly tools: BoardToolRules;\n /** Integration event handlers for cards on this board; empty when the board declares none. */\n readonly events: BoardEventRules;\n /** @deprecated Express the flow with each phase's `nextPhases` and `exitTool`; still enforced when set. */\n readonly transitionPolicy?: BoardTransitionPolicy;\n /** Where source-closed rules move a card; absent when the board opts out of auto-closing. */\n readonly sourceClosed?: BoardSourceClosed<PhaseId>;\n allowsTransition(from: PhaseId, to: PhaseId): boolean;\n /** Declared kind of a phase, or undefined when the board has no such phase. */\n phaseKind(phase: string): BoardPhaseKind | undefined;\n isWorking(phase: string): boolean;\n isTerminal(phase: string): boolean;\n /** Session context of a working phase; undefined for resting/terminal/unknown phases. */\n roleForPhase(phase: string): string | undefined;\n /** First working phase, in declaration order, running in `role`'s context. */\n phaseForRole(role: string): PhaseId | undefined;\n /**\n * Whether the phase's runs start without anyone approving them, for a card with these facts\n * (`cardRuleFacts`). A phase with a start condition never starts on its own without facts.\n */\n startsAutomatically(phase: string, facts?: RuleFacts): boolean;\n}\n\ntype BoardConfig<BoardId extends string, Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>> = {\n id: BoardId;\n name?: string;\n /** @deprecated Use `name`. */\n title?: string;\n description?: string;\n initialPhase: keyof Phases & string;\n phases: Phases;\n tools?: Record<string, BoardToolRule>;\n events?: BoardEventRules;\n /** @deprecated Express the flow with each phase's `nextPhases` and `exitTool`; still enforced when set. */\n transitionPolicy?: BoardTransitionPolicy;\n sourceClosed?: { completed: keyof Phases & string; canceled: keyof Phases & string };\n};\n\nexport class BoardDefinitionError extends Error {\n override name = 'BoardDefinitionError';\n}\n\nconst PHASE_KINDS: ReadonlySet<string> = new Set<BoardPhaseKind>(['resting', 'working', 'terminal']);\n\nfunction validateBoardIdentifier(value: unknown, label: string): void {\n if (!isBoardIdentifier(value)) {\n throw new BoardDefinitionError(`${label} must be a valid board identifier.`);\n }\n}\n\nconst MAX_NAME_LENGTH = 128;\nconst MAX_DESCRIPTION_LENGTH = 2_000;\nconst MAX_INSTRUCTIONS_LENGTH = 1_000;\nconst RUNNER_KEYS: ReadonlySet<string> = new Set(['agentId', 'skill', 'context', 'instructions']);\nconst EXIT_TOOL_KEYS: ReadonlySet<string> = new Set(['id', 'autoApprove', 'autoApproveWhen']);\nconst WORKING_ONLY_FIELDS = ['runner', 'autoStart', 'autoStartWhen', 'exitTool'] as const;\nconst MOVE_TOOL = 'factory_transition_work_item';\n\n/** `name`, falling back to the deprecated `title`; both may be set only to the same text. */\nfunction resolveName(name: unknown, title: unknown, label: string): string {\n if (name !== undefined && title !== undefined && name !== title) {\n throw new BoardDefinitionError(`${label} sets both name and title; drop the deprecated title.`);\n }\n const value = name ?? title;\n if (typeof value !== 'string' || value.trim().length === 0 || value.length > MAX_NAME_LENGTH) {\n throw new BoardDefinitionError(`${label} must declare a name.`);\n }\n return value;\n}\n\nfunction optionalText(value: unknown, label: string, max: number): string | undefined {\n if (value === undefined) return undefined;\n if (typeof value !== 'string' || value.trim().length === 0 || value.length > max) {\n throw new BoardDefinitionError(`${label} must be non-empty text of at most ${max} characters.`);\n }\n return value;\n}\n\nfunction ruleGroup(value: unknown, label: string): RuleGroup | undefined {\n if (value === undefined) return undefined;\n const parsed = cardRuleGroupSchema.safeParse(value);\n if (!parsed.success) {\n throw new BoardDefinitionError(`${label} is not a valid condition: ${parsed.error.issues[0]?.message}`);\n }\n return parsed.data;\n}\n\nfunction isContext(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0 && value.length <= MAX_ROLE_LENGTH && IDENTIFIER_RE.test(value);\n}\n\nfunction resolveRunner(phaseId: string, phase: BoardPhaseDefinition<string>): ResolvedRunner {\n const runner: unknown = phase.runner ?? {};\n if (!isPlainObject(runner) || Object.keys(runner).some(key => !RUNNER_KEYS.has(key))) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner may only set agentId, skill, context and instructions.`);\n }\n const role: unknown = phase.role;\n if (role !== undefined && runner.context !== undefined && role !== runner.context) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" sets both role and runner.context; drop the deprecated role.`);\n }\n const context = runner.context ?? role ?? DEFAULT_PHASE_CONTEXT;\n if (!isContext(context)) throw new BoardDefinitionError(`Working phase \"${phaseId}\" must declare a valid context.`);\n const agentId = runner.agentId ?? FACTORY_AGENT_ID;\n if (agentId !== FACTORY_AGENT_ID) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" names unknown agent \"${String(agentId)}\"; Factory runs \"${FACTORY_AGENT_ID}\".`,\n );\n }\n const skill = runner.skill;\n if (\n skill !== undefined &&\n (typeof skill !== 'string' || skill.length > MAX_SKILL_NAME_LENGTH || !SKILL_NAME_RE.test(skill))\n ) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.skill must be a skill name.`);\n }\n const instructions = optionalText(\n runner.instructions,\n `Phase \"${phaseId}\" runner.instructions`,\n MAX_INSTRUCTIONS_LENGTH,\n );\n return Object.freeze({\n agentId,\n context,\n ...(skill !== undefined ? { skill } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n });\n}\n\nfunction resolveExitTool(phaseId: string, value: unknown): ResolvedExitTool {\n if (value === undefined) return undefined;\n const declared = typeof value === 'string' ? { id: value } : value;\n if (!isPlainObject(declared) || Object.keys(declared).some(key => !EXIT_TOOL_KEYS.has(key))) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" exitTool must be a tool name or { id, autoApprove, autoApproveWhen }.`,\n );\n }\n const { id, autoApprove = false } = declared;\n if (typeof id !== 'string' || id.length === 0 || id.length > MAX_TOOL_NAME_LENGTH || !IDENTIFIER_RE.test(id)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool has an invalid tool name.`);\n }\n if (id === MOVE_TOOL) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" cannot end with ${MOVE_TOOL}: that tool already moves the card.`,\n );\n }\n if (typeof autoApprove !== 'boolean') {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool.autoApprove must be a boolean.`);\n }\n const autoApproveWhen = ruleGroup(declared.autoApproveWhen, `Phase \"${phaseId}\" exitTool.autoApproveWhen`);\n if (autoApproveWhen && !autoApprove) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool.autoApproveWhen needs autoApprove.`);\n }\n return Object.freeze({ id, autoApprove, ...(autoApproveWhen ? { autoApproveWhen } : {}) });\n}\n\nfunction validatePhaseSemantics(phaseId: string, phase: BoardPhaseDefinition<string>): void {\n if (!PHASE_KINDS.has(phase.kind as string)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" must declare kind 'resting', 'working', or 'terminal'.`);\n }\n if (phase.kind === 'working') return;\n if ((phase as { role?: unknown }).role !== undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" is ${phase.kind} and cannot declare a role.`);\n }\n for (const field of WORKING_ONLY_FIELDS) {\n if ((phase as Record<string, unknown>)[field] !== undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" is ${phase.kind} and cannot declare ${field}.`);\n }\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction validateToolRules(tools: unknown): BoardToolRules {\n if (tools === undefined) return Object.freeze({});\n if (!isPlainObject(tools)) throw new BoardDefinitionError('Board tools must be a plain object.');\n const frozen: Record<string, BoardToolRule> = {};\n for (const [toolName, leaf] of Object.entries(tools)) {\n if (toolName.length === 0 || toolName.length > MAX_TOOL_NAME_LENGTH || !IDENTIFIER_RE.test(toolName)) {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" has an invalid tool name.`);\n }\n if (!isPlainObject(leaf) || Object.keys(leaf).some(key => key !== 'onResult')) {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" must be an object with only onResult.`);\n }\n if (typeof leaf.onResult !== 'function') {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" must declare an onResult function.`);\n }\n frozen[toolName] = Object.freeze({ onResult: leaf.onResult as BoardToolResultRuleHandler });\n }\n return Object.freeze(frozen);\n}\n\nfunction validateSourceClosed(\n sourceClosed: unknown,\n phases: Readonly<Record<string, BoardPhaseDefinition<string>>>,\n): BoardSourceClosed<string> | undefined {\n if (sourceClosed === undefined) return undefined;\n if (!isPlainObject(sourceClosed)) throw new BoardDefinitionError('Board sourceClosed must be a plain object.');\n const keys = Object.keys(sourceClosed);\n if (keys.length !== 2 || !keys.includes('completed') || !keys.includes('canceled')) {\n throw new BoardDefinitionError('Board sourceClosed must declare exactly completed and canceled.');\n }\n for (const key of ['completed', 'canceled'] as const) {\n const phase = sourceClosed[key];\n if (typeof phase !== 'string' || !Object.hasOwn(phases, phase) || phases[phase]!.kind !== 'terminal') {\n throw new BoardDefinitionError(`Board sourceClosed.${key} \"${String(phase)}\" must name a terminal phase.`);\n }\n }\n return Object.freeze({ completed: sourceClosed.completed as string, canceled: sourceClosed.canceled as string });\n}\n\nfunction validateEventRules(events: unknown): BoardEventRules {\n if (events === undefined) return Object.freeze({});\n if (!isPlainObject(events)) throw new BoardDefinitionError('Board events must be a plain object.');\n const frozen: Record<string, Readonly<Record<string, unknown>>> = {};\n for (const [integration, handlers] of Object.entries(events)) {\n const known = Object.hasOwn(BOARD_EVENT_NAMES, integration)\n ? BOARD_EVENT_NAMES[integration as BoardEventIntegration]\n : undefined;\n if (!known) throw new BoardDefinitionError(`Board events name unknown integration \"${integration}\".`);\n if (handlers === undefined) continue;\n if (!isPlainObject(handlers)) {\n throw new BoardDefinitionError(`Board events for \"${integration}\" must be a plain object.`);\n }\n const entries: Record<string, unknown> = {};\n for (const [event, handler] of Object.entries(handlers)) {\n if (!known.includes(event)) {\n throw new BoardDefinitionError(`Board events for \"${integration}\" name unknown event \"${event}\".`);\n }\n if (handler === undefined) continue;\n if (handler !== null && typeof handler !== 'function') {\n throw new BoardDefinitionError(`Board event handler \"${integration}.${event}\" must be a function or null.`);\n }\n entries[event] = handler;\n }\n frozen[integration] = Object.freeze(entries);\n }\n return Object.freeze(frozen) as BoardEventRules;\n}\n\n/** The phase's `onEnter` handlers, with its runner's skill for other sources and its instructions on every run. */\nfunction phaseEnterHandlers(\n declared: ReadonlyBoardPhaseHandlers | undefined,\n runner: ResolvedRunner,\n): ReadonlyBoardPhaseHandlers | undefined {\n const handlers: BoardPhaseHandlers = { ...declared };\n if (runner.skill) {\n for (const source of FACTORY_RULE_SOURCES) handlers[source] ??= startSkill(runner.skill, runner.context);\n }\n if (runner.instructions) {\n for (const source of Object.keys(handlers) as FactoryRuleSource[]) {\n handlers[source] = addInstructions(handlers[source]!, runner.instructions);\n }\n }\n return Object.keys(handlers).length > 0 ? handlers : undefined;\n}\n\nconst warnedBoards = new Set<string>();\n\ntype DeclaredBoard = {\n readonly id: string;\n readonly name?: string;\n readonly title?: string;\n readonly transitionPolicy?: BoardTransitionPolicy;\n readonly phases: Readonly<Record<string, BoardPhaseDefinition<string>>>;\n};\n\n/**\n * Deprecated fields a board declaration still relies on; `defineBoard()` maps each to its\n * replacement. A deprecated field next to its replacement adds nothing, so it is not reported:\n * that is how a resolved board, which carries both, is declared again.\n */\nfunction deprecatedFields(config: DeclaredBoard): string[] {\n const found: string[] = [];\n if (config.title !== undefined && config.name === undefined) found.push('title → name');\n if (config.transitionPolicy !== undefined) found.push('transitionPolicy → phases.*.nextPhases and exitTool');\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n if (phase.title !== undefined && phase.name === undefined) found.push(`phases.${phaseId}.title → name`);\n if (phase.next !== undefined && !phase.nextPhases?.includes(phase.next)) {\n found.push(`phases.${phaseId}.next → nextPhases`);\n }\n if (phase.role !== undefined && phase.runner?.context === undefined) {\n found.push(`phases.${phaseId}.role → runner.context`);\n }\n }\n return found;\n}\n\nfunction warnDeprecatedFields(config: DeclaredBoard): void {\n if (warnedBoards.has(config.id)) return;\n const found = deprecatedFields(config);\n if (found.length === 0) return;\n warnedBoards.add(config.id);\n console.warn(\n `[Mastra Factory] Board \"${config.id}\" uses deprecated fields: ${found.join(', ')}. ` +\n 'They still work but will be removed in a future release.',\n );\n}\n\n/** Marks a board an app declared with the deprecated `defineBoard()`; a copy does not carry it. */\nconst DEFINED_BOARD = Symbol('DefinedBoard');\n\n/**\n * Declares a board in code.\n *\n * @deprecated Boards are stored per project; manage them with `/web/factory/projects/:id/boards`\n * (README § Stored boards). Code boards are read-only and served alongside each project's stored\n * boards.\n */\nexport function defineBoard<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(config: BoardConfig<BoardId, Phases>): BoardDefinition<BoardId, keyof Phases & string> {\n return buildBoard(config, true);\n}\n\n/** Whether an app declared the board with the deprecated `defineBoard()`. */\nexport function isDefinedBoard(board: object): boolean {\n return DEFINED_BOARD in board;\n}\n\n/** Validates and resolves a board declaration. Factory's own boards use this directly. */\nexport function compileBoardDefinition<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(config: BoardConfig<BoardId, Phases>): BoardDefinition<BoardId, keyof Phases & string> {\n return buildBoard(config, false);\n}\n\nfunction buildBoard<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(config: BoardConfig<BoardId, Phases>, defined: boolean): BoardDefinition<BoardId, keyof Phases & string> {\n type PhaseId = keyof Phases & string;\n validateBoardIdentifier(config.id, 'Board id');\n const boardName = resolveName(config.name, config.title, `Board \"${config.id}\"`);\n const boardDescription = optionalText(config.description, `Board \"${config.id}\" description`, MAX_DESCRIPTION_LENGTH);\n if (config.transitionPolicy !== undefined && typeof config.transitionPolicy !== 'function') {\n throw new BoardDefinitionError('Board transitionPolicy must be a function.');\n }\n const tools = validateToolRules(config.tools);\n const events = validateEventRules(config.events);\n const phaseIds = new Set(Object.keys(config.phases));\n if (phaseIds.size === 0) throw new BoardDefinitionError('A board must define at least one phase.');\n if (!phaseIds.has(config.initialPhase)) {\n throw new BoardDefinitionError(`Initial phase \"${config.initialPhase}\" is not defined.`);\n }\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n validateBoardIdentifier(phaseId, 'Phase id');\n validatePhaseSemantics(phaseId, phase);\n }\n if (config.phases[config.initialPhase]!.kind !== 'resting') {\n throw new BoardDefinitionError(`Initial phase \"${config.initialPhase}\" must be a resting phase.`);\n }\n warnDeprecatedFields(config);\n const sourceClosed = validateSourceClosed(config.sourceClosed, config.phases) as\n | BoardSourceClosed<PhaseId>\n | undefined;\n\n const transitions = Object.fromEntries(\n Object.entries(config.phases).map(([phaseId, phase]) => {\n if (phase.next !== undefined && phase.outcomes) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" cannot define both next and outcomes.`);\n }\n if (phase.nextPhases !== undefined && !Array.isArray(phase.nextPhases)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" nextPhases must be a list of phases.`);\n }\n const targets: BoardTransition<string>[] =\n phase.next !== undefined\n ? [Object.freeze({ outcome: null, to: phase.next })]\n : Object.entries(phase.outcomes ?? {}).map(([outcome, to]) => Object.freeze({ outcome, to }));\n for (const to of phase.nextPhases ?? []) {\n if (!targets.some(target => target.to === to)) targets.push(Object.freeze({ outcome: null, to }));\n }\n for (const { to } of targets) {\n if (!phaseIds.has(to)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" targets undefined phase \"${to}\".`);\n }\n }\n return [phaseId, Object.freeze(targets)];\n }),\n ) as Record<PhaseId, readonly BoardTransition<PhaseId>[]>;\n\n const phases = Object.freeze(\n Object.fromEntries(\n Object.entries(config.phases).map(([phaseId, phase]) => {\n const label = `Phase \"${phaseId}\"`;\n const nextPhases = Object.freeze([\n ...new Set([...(phase.nextPhases ?? []), ...transitions[phaseId as PhaseId]!.map(({ to }) => to)]),\n ]);\n const runner = phase.kind === 'working' ? resolveRunner(phaseId, phase) : undefined;\n const working = phase.kind === 'working' ? phase : undefined;\n if (working?.autoStart !== undefined && typeof working.autoStart !== 'boolean') {\n throw new BoardDefinitionError(`${label} autoStart must be a boolean.`);\n }\n const autoStartWhen = ruleGroup(working?.autoStartWhen, `${label} autoStartWhen`);\n if (autoStartWhen && working?.autoStart !== true) {\n throw new BoardDefinitionError(`${label} autoStartWhen needs autoStart.`);\n }\n const exitTool = resolveExitTool(phaseId, working?.exitTool);\n if (exitTool && nextPhases.length === 0) {\n throw new BoardDefinitionError(`${label} exit tool needs a next phase to move the card to.`);\n }\n const onEnter = runner ? phaseEnterHandlers(phase.onEnter, runner) : phase.onEnter;\n const name = resolveName(phase.name, phase.title, label);\n const description = optionalText(phase.description, `${label} description`, MAX_DESCRIPTION_LENGTH);\n return [\n phaseId,\n Object.freeze({\n name,\n title: name,\n ...(description !== undefined ? { description } : {}),\n kind: phase.kind,\n nextPhases,\n ...(phase.next !== undefined ? { next: phase.next } : {}),\n ...(phase.outcomes ? { outcomes: Object.freeze({ ...phase.outcomes }) } : {}),\n ...(runner ? { runner, role: runner.context } : {}),\n ...(working?.autoStart ? { autoStart: true } : {}),\n ...(autoStartWhen ? { autoStartWhen } : {}),\n ...(exitTool ? { exitTool } : {}),\n ...(onEnter ? { onEnter: Object.freeze({ ...onEnter }) } : {}),\n ...(phase.onExit ? { onExit: Object.freeze({ ...phase.onExit }) } : {}),\n }),\n ];\n }),\n ),\n ) as Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\n const rules = Object.freeze(\n Object.fromEntries(\n (Object.entries(phases) as [PhaseId, BoardPhase<PhaseId>][]).flatMap(([phaseId, phase]) => {\n const sources = new Set([...Object.keys(phase.onEnter ?? {}), ...Object.keys(phase.onExit ?? {})]);\n if (sources.size === 0) return [];\n return [\n [\n phaseId,\n Object.freeze(\n Object.fromEntries(\n [...sources].map(source => [\n source,\n Object.freeze({\n ...(phase.onEnter?.[source as FactoryRuleSource]\n ? { onEnter: phase.onEnter[source as FactoryRuleSource] }\n : {}),\n ...(phase.onExit?.[source as FactoryRuleSource]\n ? { onExit: phase.onExit[source as FactoryRuleSource] }\n : {}),\n }),\n ]),\n ),\n ),\n ],\n ];\n }),\n ),\n ) as ReadonlyFactoryBoardRules;\n\n const kinds = new Map<string, BoardPhaseKind>();\n const roles = new Map<string, string>();\n const phaseByRole = new Map<string, PhaseId>();\n for (const [phaseId, phase] of Object.entries(phases) as [PhaseId, BoardPhase<PhaseId>][]) {\n kinds.set(phaseId, phase.kind);\n if (phase.kind !== 'working') continue;\n roles.set(phaseId, phase.runner.context);\n if (!phaseByRole.has(phase.runner.context)) phaseByRole.set(phase.runner.context, phaseId);\n }\n\n const board = {\n id: config.id,\n name: boardName,\n title: boardName,\n ...(boardDescription !== undefined ? { description: boardDescription } : {}),\n initialPhase: config.initialPhase,\n phases,\n transitions: Object.freeze(transitions),\n rules: Object.freeze(rules),\n tools,\n events,\n ...(config.transitionPolicy ? { transitionPolicy: config.transitionPolicy } : {}),\n ...(sourceClosed ? { sourceClosed } : {}),\n allowsTransition(from: PhaseId, to: PhaseId) {\n return from === to || transitions[from]?.some(transition => transition.to === to) === true;\n },\n phaseKind: (phase: string) => kinds.get(phase),\n isWorking: (phase: string) => kinds.get(phase) === 'working',\n isTerminal: (phase: string) => kinds.get(phase) === 'terminal',\n roleForPhase: (phase: string) => roles.get(phase),\n phaseForRole: (role: string) => phaseByRole.get(role),\n startsAutomatically: (phase: string, facts?: RuleFacts) => {\n const definition = phases[phase as PhaseId] as BoardPhase<PhaseId> | undefined;\n if (definition?.kind !== 'working' || definition.autoStart !== true) return false;\n if (!definition.autoStartWhen) return true;\n return facts !== undefined && evaluateRuleGroup(definition.autoStartWhen, facts);\n },\n };\n if (defined) Object.defineProperty(board,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E,cAAc,OAAO;EACrB;EACA,aAAa,OAAO,OAAO,WAAW;EACtC,OAAO,OAAO,OAAO,KAAK;EAC1B;EACA;EACA,GAAI,OAAO,mBAAmB,EAAE,kBAAkB,OAAO,iBAAiB,IAAI,CAAC;EAC/E,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;EACvC,iBAAiB,MAAe,IAAa;GAC3C,OAAO,SAAS,MAAM,YAAY,KAAK,EAAE,MAAK,eAAc,WAAW,OAAO,EAAE,MAAM;EACxF;EACA,YAAY,UAAkB,MAAM,IAAI,KAAK;EAC7C,YAAY,UAAkB,MAAM,IAAI,KAAK,MAAM;EACnD,aAAa,UAAkB,MAAM,IAAI,KAAK,MAAM;EACpD,eAAe,UAAkB,MAAM,IAAI,KAAK;EAChD,eAAe,SAAiB,YAAY,IAAI,IAAI;EACpD,sBAAsB,OAAe,UAAsB;GACzD,MAAM,aAAa,OAAO;GAC1B,IAAI,YAAY,SAAS,aAAa,WAAW,cAAc,MAAM,OAAO;GAC5E,IAAI,CAAC,WAAW,eAAe,OAAO;GACtC,OAAO,UAAU,KAAA,KAAa,kBAAkB,WAAW,eAAe,KAAK;EACjF;CACF;CACA,IAAI,SAAS,OAAO,eAAe,OAAO,eAAe,EAAE,OAAO,KAAK,CAAC;CACxE,OAAO,OAAO,OAAO,KAAK;AAC5B"}
1
+ {"version":3,"file":"define-board.js","names":[],"sources":["../../src/boards/define-board.ts"],"sourcesContent":["import { CODE_AGENT_ID } from '@mastra/code-sdk/constants';\nimport { cardRuleGroupSchema, evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { RuleFacts, RuleGroup } from '../rules/rule-group.js';\nimport {\n FACTORY_GITHUB_EVENTS,\n FACTORY_RULE_SOURCES,\n FACTORY_GITLAB_EVENTS,\n FACTORY_INCIDENTIO_EVENTS,\n FACTORY_JIRA_EVENTS,\n FACTORY_LINEAR_EVENTS,\n} from '../rules/types.js';\nimport type {\n FactoryGithubEventName,\n FactoryGithubRuleContext,\n FactoryGitLabEventName,\n FactoryGitLabRuleContext,\n FactoryIncidentioEventName,\n FactoryIncidentioRuleContext,\n FactoryJiraEventName,\n FactoryJiraRuleContext,\n FactoryLinearEventName,\n FactoryLinearRuleContext,\n FactoryRuleHandler,\n FactoryRuleSource,\n FactoryStageRuleContext,\n FactoryToolResultRuleContext,\n} from '../rules/types.js';\nimport {\n IDENTIFIER_RE,\n isBoardIdentifier,\n MAX_ROLE_LENGTH,\n MAX_SKILL_NAME_LENGTH,\n MAX_TOOL_NAME_LENGTH,\n SKILL_NAME_RE,\n} from '../rules/validation.js';\nimport { addInstructions, startSkill } from './phase-runner.js';\nimport type { BoardTransitionPolicy } from './transition-policy.js';\n\ntype BoardPhaseHandlers = Partial<Record<FactoryRuleSource, FactoryRuleHandler<FactoryStageRuleContext>>>;\ntype ReadonlyBoardPhaseHandlers = Readonly<BoardPhaseHandlers>;\n\n/** Runs when an agent seated on this board completes the named tool. */\nexport type BoardToolResultRuleHandler = FactoryRuleHandler<FactoryToolResultRuleContext>;\nexport type BoardToolRule = { readonly onResult: BoardToolResultRuleHandler };\nexport type BoardToolRules = Readonly<Record<string, BoardToolRule>>;\n\n/**\n * A board's handler for one integration event. `null` switches the integration default off\n * for cards on this board only.\n */\ntype BoardEventHandlerMap<EventName extends string, Context> = Readonly<\n Partial<Record<EventName, FactoryRuleHandler<Context> | null>>\n>;\n\n/**\n * How cards on this board react to integration events, keyed by integration then event.\n * Consulted for events bound to a card on this board, after any handler the deployment set\n * explicitly on the integration and before the integration default.\n */\nexport interface BoardEventRules {\n readonly github?: BoardEventHandlerMap<FactoryGithubEventName, FactoryGithubRuleContext>;\n readonly gitlab?: BoardEventHandlerMap<FactoryGitLabEventName, FactoryGitLabRuleContext>;\n readonly linear?: BoardEventHandlerMap<FactoryLinearEventName, FactoryLinearRuleContext>;\n readonly jira?: BoardEventHandlerMap<FactoryJiraEventName, FactoryJiraRuleContext>;\n readonly incidentio?: BoardEventHandlerMap<FactoryIncidentioEventName, FactoryIncidentioRuleContext>;\n}\nexport type BoardEventIntegration = keyof BoardEventRules;\n\nconst BOARD_EVENT_NAMES: Readonly<Record<BoardEventIntegration, readonly string[]>> = {\n github: FACTORY_GITHUB_EVENTS,\n gitlab: FACTORY_GITLAB_EVENTS,\n linear: FACTORY_LINEAR_EVENTS,\n jira: FACTORY_JIRA_EVENTS,\n incidentio: FACTORY_INCIDENTIO_EVENTS,\n};\n\ntype ReadonlyFactoryBoardRules = Readonly<\n Record<\n string,\n Readonly<\n Partial<\n Record<\n FactoryRuleSource,\n Readonly<{\n onEnter?: FactoryRuleHandler<FactoryStageRuleContext>;\n onExit?: FactoryRuleHandler<FactoryStageRuleContext>;\n }>\n >\n >\n >\n >\n>;\n\n/**\n * What a phase means to the runtime.\n * - `resting`: nobody is seated; a card waits for a person or an event.\n * - `working`: an agent in the phase's context carries the card; a person's move in arms autonomy.\n * - `terminal`: the card is finished; sessions stop and held resources are released.\n */\nexport type BoardPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** The agent Factory runs every phase with. */\nexport const FACTORY_AGENT_ID = CODE_AGENT_ID;\n\n/** The session context a working phase runs in when it names none. */\nexport const DEFAULT_PHASE_CONTEXT = 'work';\n\n/** Who runs a working phase, and with what. */\nexport interface BoardPhaseRunner {\n /** Must be `code-agent`, the agent Factory runs; omitted means that agent. */\n readonly agentId?: string;\n /** Skill started when a card enters the phase from a source with no `onEnter` handler. */\n readonly skill?: string;\n /**\n * The session the phase runs in. Phases naming the same context share one session per card;\n * a different context gets its own. Defaults to `work`.\n */\n readonly context?: string;\n /** Appended to every run the phase starts. */\n readonly instructions?: string;\n}\n\n/**\n * The tool whose successful call ends a working phase. The agent then moves the card itself with\n * `factory_transition_work_item`, to one of the phase's `nextPhases`.\n */\nexport interface BoardPhaseExitTool {\n readonly id: string;\n /**\n * Answer the approval the tool waits for without a person. Factory sessions run other tools\n * without asking, so today this applies to `submit_plan`. Defaults to false.\n */\n readonly autoApprove?: boolean;\n /** With `autoApprove`, only cards this matches are approved without a person. */\n readonly autoApproveWhen?: RuleGroup;\n}\n\ntype BoardPhaseBase<PhaseId extends string> = {\n readonly name?: string;\n /** @deprecated Use `name`. */\n readonly title?: string;\n readonly description?: string;\n /** Phases a card may move to from here. */\n readonly nextPhases?: readonly PhaseId[];\n /** @deprecated List the phase in `nextPhases`. */\n readonly next?: PhaseId;\n /** Named moves rules can choose by outcome; each target is also an allowed next phase. */\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n readonly onEnter?: ReadonlyBoardPhaseHandlers;\n readonly onExit?: ReadonlyBoardPhaseHandlers;\n};\n\ntype WorkingPhaseFields = {\n readonly runner?: BoardPhaseRunner;\n /** @deprecated Use `runner.context`. */\n readonly role?: string;\n /** Runs start without anyone approving them, even with the project's auto-run off. */\n readonly autoStart?: boolean;\n /** With `autoStart`, only cards this matches start on their own. */\n readonly autoStartWhen?: RuleGroup;\n /** A bare tool name is shorthand for `{ id }`, with nothing approved on a person's behalf. */\n readonly exitTool?: string | BoardPhaseExitTool;\n};\n\ntype NonWorkingPhaseFields = {\n readonly runner?: never;\n readonly role?: never;\n readonly autoStart?: never;\n readonly autoStartWhen?: never;\n readonly exitTool?: never;\n};\n\n/** A phase as a board declares it. */\nexport type BoardPhaseDefinition<PhaseId extends string> =\n | (BoardPhaseBase<PhaseId> & NonWorkingPhaseFields & { readonly kind: 'resting' })\n | (BoardPhaseBase<PhaseId> & WorkingPhaseFields & { readonly kind: 'working' })\n | (BoardPhaseBase<PhaseId> & NonWorkingPhaseFields & { readonly kind: 'terminal' });\n\ntype ResolvedPhaseBase<PhaseId extends string> = {\n readonly name: string;\n /** @deprecated Use `name`; kept equal to it for code written against older Factory versions. */\n readonly title: string;\n readonly description?: string;\n /** Every phase a card may move to from here, including outcome targets. */\n readonly nextPhases: readonly PhaseId[];\n /** @deprecated Use `nextPhases`; set when the phase declared `next`. */\n readonly next?: PhaseId;\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n readonly onEnter?: ReadonlyBoardPhaseHandlers;\n readonly onExit?: ReadonlyBoardPhaseHandlers;\n};\n\n/**\n * A phase as the board resolved it: deprecated fields are replaced by their new names, so\n * only the new structure leaves `defineBoard()`, and a resolved phase can be declared again.\n */\nexport type BoardPhase<PhaseId extends string> =\n | (ResolvedPhaseBase<PhaseId> & { readonly kind: 'resting' })\n | (ResolvedPhaseBase<PhaseId> & {\n readonly kind: 'working';\n readonly runner: Readonly<BoardPhaseRunner & { agentId: string; context: string }>;\n /** @deprecated Use `runner.context`; kept equal to it. */\n readonly role: string;\n readonly autoStart?: boolean;\n readonly autoStartWhen?: RuleGroup;\n readonly exitTool?: Readonly<{ id: string; autoApprove: boolean; autoApproveWhen?: RuleGroup }>;\n })\n | (ResolvedPhaseBase<PhaseId> & { readonly kind: 'terminal' });\n\ntype ResolvedRunner = Extract<BoardPhase<string>, { kind: 'working' }>['runner'];\ntype ResolvedExitTool = Extract<BoardPhase<string>, { kind: 'working' }>['exitTool'];\n\nexport interface BoardTransition<PhaseId extends string> {\n readonly outcome: string | null;\n readonly to: PhaseId;\n}\n\n/**\n * Terminal phases a card moves to when its tracked source (issue or follow-up) closes.\n * `completed` is used when the source was completed, `canceled` when it was canceled or not planned.\n */\nexport type BoardSourceClosed<PhaseId extends string> = Readonly<{ completed: PhaseId; canceled: PhaseId }>;\n\nexport interface BoardDefinition<BoardId extends string, PhaseId extends string> {\n readonly id: BoardId;\n readonly name: string;\n /** @deprecated Use `name`; kept equal to it for code written against older Factory versions. */\n readonly title: string;\n readonly description?: string;\n readonly initialPhase: PhaseId;\n readonly phases: Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\n readonly transitions: Readonly<Record<PhaseId, readonly BoardTransition<PhaseId>[]>>;\n readonly rules: ReadonlyFactoryBoardRules;\n /** Tool-result rules keyed by tool name; empty when the board declares none. */\n readonly tools: BoardToolRules;\n /** Integration event handlers for cards on this board; empty when the board declares none. */\n readonly events: BoardEventRules;\n /** @deprecated Express the flow with each phase's `nextPhases` and `exitTool`; still enforced when set. */\n readonly transitionPolicy?: BoardTransitionPolicy;\n /** Where source-closed rules move a card; absent when the board opts out of auto-closing. */\n readonly sourceClosed?: BoardSourceClosed<PhaseId>;\n allowsTransition(from: PhaseId, to: PhaseId): boolean;\n /** Declared kind of a phase, or undefined when the board has no such phase. */\n phaseKind(phase: string): BoardPhaseKind | undefined;\n isWorking(phase: string): boolean;\n isTerminal(phase: string): boolean;\n /** Session context of a working phase; undefined for resting/terminal/unknown phases. */\n roleForPhase(phase: string): string | undefined;\n /** First working phase, in declaration order, running in `role`'s context. */\n phaseForRole(role: string): PhaseId | undefined;\n /**\n * Whether the phase's runs start without anyone approving them, for a card with these facts\n * (`cardRuleFacts`). A phase with a start condition never starts on its own without facts.\n */\n startsAutomatically(phase: string, facts?: RuleFacts): boolean;\n}\n\ntype BoardConfig<BoardId extends string, Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>> = {\n id: BoardId;\n name?: string;\n /** @deprecated Use `name`. */\n title?: string;\n description?: string;\n initialPhase: keyof Phases & string;\n phases: Phases;\n tools?: Record<string, BoardToolRule>;\n events?: BoardEventRules;\n /** @deprecated Express the flow with each phase's `nextPhases` and `exitTool`; still enforced when set. */\n transitionPolicy?: BoardTransitionPolicy;\n sourceClosed?: { completed: keyof Phases & string; canceled: keyof Phases & string };\n};\n\nexport class BoardDefinitionError extends Error {\n override name = 'BoardDefinitionError';\n}\n\nconst PHASE_KINDS: ReadonlySet<string> = new Set<BoardPhaseKind>(['resting', 'working', 'terminal']);\n\nfunction validateBoardIdentifier(value: unknown, label: string): void {\n if (!isBoardIdentifier(value)) {\n throw new BoardDefinitionError(`${label} must be a valid board identifier.`);\n }\n}\n\nconst MAX_NAME_LENGTH = 128;\nconst MAX_DESCRIPTION_LENGTH = 2_000;\nconst MAX_INSTRUCTIONS_LENGTH = 1_000;\nconst RUNNER_KEYS: ReadonlySet<string> = new Set(['agentId', 'skill', 'context', 'instructions']);\nconst EXIT_TOOL_KEYS: ReadonlySet<string> = new Set(['id', 'autoApprove', 'autoApproveWhen']);\nconst WORKING_ONLY_FIELDS = ['runner', 'autoStart', 'autoStartWhen', 'exitTool'] as const;\nconst MOVE_TOOL = 'factory_transition_work_item';\n\n/** `name`, falling back to the deprecated `title`; both may be set only to the same text. */\nfunction resolveName(name: unknown, title: unknown, label: string): string {\n if (name !== undefined && title !== undefined && name !== title) {\n throw new BoardDefinitionError(`${label} sets both name and title; drop the deprecated title.`);\n }\n const value = name ?? title;\n if (typeof value !== 'string' || value.trim().length === 0 || value.length > MAX_NAME_LENGTH) {\n throw new BoardDefinitionError(`${label} must declare a name.`);\n }\n return value;\n}\n\nfunction optionalText(value: unknown, label: string, max: number): string | undefined {\n if (value === undefined) return undefined;\n if (typeof value !== 'string' || value.trim().length === 0 || value.length > max) {\n throw new BoardDefinitionError(`${label} must be non-empty text of at most ${max} characters.`);\n }\n return value;\n}\n\nfunction ruleGroup(value: unknown, label: string): RuleGroup | undefined {\n if (value === undefined) return undefined;\n const parsed = cardRuleGroupSchema.safeParse(value);\n if (!parsed.success) {\n throw new BoardDefinitionError(`${label} is not a valid condition: ${parsed.error.issues[0]?.message}`);\n }\n return parsed.data;\n}\n\nfunction isContext(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0 && value.length <= MAX_ROLE_LENGTH && IDENTIFIER_RE.test(value);\n}\n\nfunction resolveRunner(phaseId: string, phase: BoardPhaseDefinition<string>): ResolvedRunner {\n const runner: unknown = phase.runner ?? {};\n if (!isPlainObject(runner) || Object.keys(runner).some(key => !RUNNER_KEYS.has(key))) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner may only set agentId, skill, context and instructions.`);\n }\n const role: unknown = phase.role;\n if (role !== undefined && runner.context !== undefined && role !== runner.context) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" sets both role and runner.context; drop the deprecated role.`);\n }\n const context = runner.context ?? role ?? DEFAULT_PHASE_CONTEXT;\n if (!isContext(context)) throw new BoardDefinitionError(`Working phase \"${phaseId}\" must declare a valid context.`);\n const agentId = runner.agentId ?? FACTORY_AGENT_ID;\n if (agentId !== FACTORY_AGENT_ID) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" names unknown agent \"${String(agentId)}\"; Factory runs \"${FACTORY_AGENT_ID}\".`,\n );\n }\n const skill = runner.skill;\n if (\n skill !== undefined &&\n (typeof skill !== 'string' || skill.length > MAX_SKILL_NAME_LENGTH || !SKILL_NAME_RE.test(skill))\n ) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.skill must be a skill name.`);\n }\n const instructions = optionalText(\n runner.instructions,\n `Phase \"${phaseId}\" runner.instructions`,\n MAX_INSTRUCTIONS_LENGTH,\n );\n return Object.freeze({\n agentId,\n context,\n ...(skill !== undefined ? { skill } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n });\n}\n\nfunction resolveExitTool(phaseId: string, value: unknown): ResolvedExitTool {\n if (value === undefined) return undefined;\n const declared = typeof value === 'string' ? { id: value } : value;\n if (!isPlainObject(declared) || Object.keys(declared).some(key => !EXIT_TOOL_KEYS.has(key))) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" exitTool must be a tool name or { id, autoApprove, autoApproveWhen }.`,\n );\n }\n const { id, autoApprove = false } = declared;\n if (typeof id !== 'string' || id.length === 0 || id.length > MAX_TOOL_NAME_LENGTH || !IDENTIFIER_RE.test(id)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool has an invalid tool name.`);\n }\n if (id === MOVE_TOOL) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" cannot end with ${MOVE_TOOL}: that tool already moves the card.`,\n );\n }\n if (typeof autoApprove !== 'boolean') {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool.autoApprove must be a boolean.`);\n }\n const autoApproveWhen = ruleGroup(declared.autoApproveWhen, `Phase \"${phaseId}\" exitTool.autoApproveWhen`);\n if (autoApproveWhen && !autoApprove) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" exitTool.autoApproveWhen needs autoApprove.`);\n }\n return Object.freeze({ id, autoApprove, ...(autoApproveWhen ? { autoApproveWhen } : {}) });\n}\n\nfunction validatePhaseSemantics(phaseId: string, phase: BoardPhaseDefinition<string>): void {\n if (!PHASE_KINDS.has(phase.kind as string)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" must declare kind 'resting', 'working', or 'terminal'.`);\n }\n if (phase.kind === 'working') return;\n if ((phase as { role?: unknown }).role !== undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" is ${phase.kind} and cannot declare a role.`);\n }\n for (const field of WORKING_ONLY_FIELDS) {\n if ((phase as Record<string, unknown>)[field] !== undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" is ${phase.kind} and cannot declare ${field}.`);\n }\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction validateToolRules(tools: unknown): BoardToolRules {\n if (tools === undefined) return Object.freeze({});\n if (!isPlainObject(tools)) throw new BoardDefinitionError('Board tools must be a plain object.');\n const frozen: Record<string, BoardToolRule> = {};\n for (const [toolName, leaf] of Object.entries(tools)) {\n if (toolName.length === 0 || toolName.length > MAX_TOOL_NAME_LENGTH || !IDENTIFIER_RE.test(toolName)) {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" has an invalid tool name.`);\n }\n if (!isPlainObject(leaf) || Object.keys(leaf).some(key => key !== 'onResult')) {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" must be an object with only onResult.`);\n }\n if (typeof leaf.onResult !== 'function') {\n throw new BoardDefinitionError(`Tool rule \"${toolName}\" must declare an onResult function.`);\n }\n frozen[toolName] = Object.freeze({ onResult: leaf.onResult as BoardToolResultRuleHandler });\n }\n return Object.freeze(frozen);\n}\n\nfunction validateSourceClosed(\n sourceClosed: unknown,\n phases: Readonly<Record<string, BoardPhaseDefinition<string>>>,\n): BoardSourceClosed<string> | undefined {\n if (sourceClosed === undefined) return undefined;\n if (!isPlainObject(sourceClosed)) throw new BoardDefinitionError('Board sourceClosed must be a plain object.');\n const keys = Object.keys(sourceClosed);\n if (keys.length !== 2 || !keys.includes('completed') || !keys.includes('canceled')) {\n throw new BoardDefinitionError('Board sourceClosed must declare exactly completed and canceled.');\n }\n for (const key of ['completed', 'canceled'] as const) {\n const phase = sourceClosed[key];\n if (typeof phase !== 'string' || !Object.hasOwn(phases, phase) || phases[phase]!.kind !== 'terminal') {\n throw new BoardDefinitionError(`Board sourceClosed.${key} \"${String(phase)}\" must name a terminal phase.`);\n }\n }\n return Object.freeze({ completed: sourceClosed.completed as string, canceled: sourceClosed.canceled as string });\n}\n\nfunction validateEventRules(events: unknown): BoardEventRules {\n if (events === undefined) return Object.freeze({});\n if (!isPlainObject(events)) throw new BoardDefinitionError('Board events must be a plain object.');\n const frozen: Record<string, Readonly<Record<string, unknown>>> = {};\n for (const [integration, handlers] of Object.entries(events)) {\n const known = Object.hasOwn(BOARD_EVENT_NAMES, integration)\n ? BOARD_EVENT_NAMES[integration as BoardEventIntegration]\n : undefined;\n if (!known) throw new BoardDefinitionError(`Board events name unknown integration \"${integration}\".`);\n if (handlers === undefined) continue;\n if (!isPlainObject(handlers)) {\n throw new BoardDefinitionError(`Board events for \"${integration}\" must be a plain object.`);\n }\n const entries: Record<string, unknown> = {};\n for (const [event, handler] of Object.entries(handlers)) {\n if (!known.includes(event)) {\n throw new BoardDefinitionError(`Board events for \"${integration}\" name unknown event \"${event}\".`);\n }\n if (handler === undefined) continue;\n if (handler !== null && typeof handler !== 'function') {\n throw new BoardDefinitionError(`Board event handler \"${integration}.${event}\" must be a function or null.`);\n }\n entries[event] = handler;\n }\n frozen[integration] = Object.freeze(entries);\n }\n return Object.freeze(frozen) as BoardEventRules;\n}\n\n/** The phase's `onEnter` handlers, with its runner's skill for other sources and its instructions on every run. */\nfunction phaseEnterHandlers(\n declared: ReadonlyBoardPhaseHandlers | undefined,\n runner: ResolvedRunner,\n): ReadonlyBoardPhaseHandlers | undefined {\n const handlers: BoardPhaseHandlers = { ...declared };\n if (runner.skill) {\n for (const source of FACTORY_RULE_SOURCES) handlers[source] ??= startSkill(runner.skill, runner.context);\n }\n if (runner.instructions) {\n for (const source of Object.keys(handlers) as FactoryRuleSource[]) {\n handlers[source] = addInstructions(handlers[source]!, runner.instructions);\n }\n }\n return Object.keys(handlers).length > 0 ? handlers : undefined;\n}\n\nconst warnedBoards = new Set<string>();\n\ntype DeclaredBoard = {\n readonly id: string;\n readonly name?: string;\n readonly title?: string;\n readonly transitionPolicy?: BoardTransitionPolicy;\n readonly phases: Readonly<Record<string, BoardPhaseDefinition<string>>>;\n};\n\n/**\n * Deprecated fields a board declaration still relies on; `defineBoard()` maps each to its\n * replacement. A deprecated field next to its replacement adds nothing, so it is not reported:\n * that is how a resolved board, which carries both, is declared again.\n */\nfunction deprecatedFields(config: DeclaredBoard): string[] {\n const found: string[] = [];\n if (config.title !== undefined && config.name === undefined) found.push('title → name');\n if (config.transitionPolicy !== undefined) found.push('transitionPolicy → phases.*.nextPhases and exitTool');\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n if (phase.title !== undefined && phase.name === undefined) found.push(`phases.${phaseId}.title → name`);\n if (phase.next !== undefined && !phase.nextPhases?.includes(phase.next)) {\n found.push(`phases.${phaseId}.next → nextPhases`);\n }\n if (phase.role !== undefined && phase.runner?.context === undefined) {\n found.push(`phases.${phaseId}.role → runner.context`);\n }\n }\n return found;\n}\n\nfunction warnDeprecatedFields(config: DeclaredBoard): void {\n if (warnedBoards.has(config.id)) return;\n const found = deprecatedFields(config);\n if (found.length === 0) return;\n warnedBoards.add(config.id);\n console.warn(\n `[Mastra Factory] Board \"${config.id}\" uses deprecated fields: ${found.join(', ')}. ` +\n 'They still work but will be removed in a future release.',\n );\n}\n\n/** Marks a board an app declared with the deprecated `defineBoard()`; a copy does not carry it. */\nconst DEFINED_BOARD = Symbol('DefinedBoard');\n\n/**\n * Declares a board in code.\n *\n * @deprecated Write the board's definition into projects with `factory.upsertBoard()`, or manage\n * it through the boards API\n * (`/web/factory/projects/:id/boards`, README \"Stored boards\"); removal is tracked in\n * mastra-ai/mastra#28920. A board defined here still works: each project stores it once and is\n * served from its row, with the code behaviour it declares.\n */\nexport function defineBoard<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(config: BoardConfig<BoardId, Phases>): BoardDefinition<BoardId, keyof Phases & string> {\n return buildBoard(config, true);\n}\n\n/** Whether an app declared the board with the deprecated `defineBoard()`. */\nexport function isDefinedBoard(board: object): boolean {\n return DEFINED_BOARD in board;\n}\n\n/** A board declaration as `defineBoard()` takes it, with any phase keys. */\nexport type AnyBoardConfig = BoardConfig<string, Record<string, BoardPhaseDefinition<string>>>;\n\n/**\n * The declaration a board was built from. A resolved board's `onEnter` handlers already carry its\n * runner's skill and instructions, so a board with other runner fields is rebuilt from this.\n */\nconst BOARD_DECLARATION = Symbol('BoardDeclaration');\n\n/** On a board built from a stored definition, the code board that gave it its behaviour. */\nconst CODE_BOARD = Symbol('CodeBoard');\n\n/** The declaration a board was built from; undefined for an object that was not built as a board. */\nexport function declarationOf(board: object): AnyBoardConfig | undefined {\n return (board as { [BOARD_DECLARATION]?: AnyBoardConfig })[BOARD_DECLARATION];\n}\n\n/** The code board a board takes its behaviour from: itself unless it was built from a stored definition. */\nexport function codeBoardOf<Board extends object>(board: Board): Board {\n return (board as { [CODE_BOARD]?: Board })[CODE_BOARD] ?? board;\n}\n\n/**\n * Validates and resolves a board declaration. Factory's own boards use this directly. A board\n * built from a stored definition names the code board whose behaviour it carries.\n */\nexport function compileBoardDefinition<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(config: BoardConfig<BoardId, Phases>, codeBoard?: object): BoardDefinition<BoardId, keyof Phases & string> {\n return buildBoard(config, false, codeBoard);\n}\n\nfunction buildBoard<\n const BoardId extends string,\n const Phases extends Record<string, BoardPhaseDefinition<keyof Phases & string>>,\n>(\n config: BoardConfig<BoardId, Phases>,\n defined: boolean,\n codeBoard?: object,\n): BoardDefinition<BoardId, keyof Phases & string> {\n type PhaseId = keyof Phases & string;\n validateBoardIdentifier(config.id, 'Board id');\n const boardName = resolveName(config.name, config.title, `Board \"${config.id}\"`);\n const boardDescription = optionalText(config.description, `Board \"${config.id}\" description`, MAX_DESCRIPTION_LENGTH);\n if (config.transitionPolicy !== undefined && typeof config.transitionPolicy !== 'function') {\n throw new BoardDefinitionError('Board transitionPolicy must be a function.');\n }\n const tools = validateToolRules(config.tools);\n const events = validateEventRules(config.events);\n const phaseIds = new Set(Object.keys(config.phases));\n if (phaseIds.size === 0) throw new BoardDefinitionError('A board must define at least one phase.');\n if (!phaseIds.has(config.initialPhase)) {\n throw new BoardDefinitionError(`Initial phase \"${config.initialPhase}\" is not defined.`);\n }\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n validateBoardIdentifier(phaseId, 'Phase id');\n validatePhaseSemantics(phaseId, phase);\n }\n if (config.phases[config.initialPhase]!.kind !== 'resting') {\n throw new BoardDefinitionError(`Initial phase \"${config.initialPhase}\" must be a resting phase.`);\n }\n warnDeprecatedFields(config);\n const sourceClosed = validateSourceClosed(config.sourceClosed, config.phases) as\n | BoardSourceClosed<PhaseId>\n | undefined;\n\n const transitions = Object.fromEntries(\n Object.entries(config.phases).map(([phaseId, phase]) => {\n if (phase.next !== undefined && phase.outcomes) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" cannot define both next and outcomes.`);\n }\n if (phase.nextPhases !== undefined && !Array.isArray(phase.nextPhases)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" nextPhases must be a list of phases.`);\n }\n const targets: BoardTransition<string>[] =\n phase.next !== undefined\n ? [Object.freeze({ outcome: null, to: phase.next })]\n : Object.entries(phase.outcomes ?? {}).map(([outcome, to]) => Object.freeze({ outcome, to }));\n for (const to of phase.nextPhases ?? []) {\n if (!targets.some(target => target.to === to)) targets.push(Object.freeze({ outcome: null, to }));\n }\n for (const { to } of targets) {\n if (!phaseIds.has(to)) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" targets undefined phase \"${to}\".`);\n }\n }\n return [phaseId, Object.freeze(targets)];\n }),\n ) as Record<PhaseId, readonly BoardTransition<PhaseId>[]>;\n\n const phases = Object.freeze(\n Object.fromEntries(\n Object.entries(config.phases).map(([phaseId, phase]) => {\n const label = `Phase \"${phaseId}\"`;\n const nextPhases = Object.freeze([\n ...new Set([...(phase.nextPhases ?? []), ...transitions[phaseId as PhaseId]!.map(({ to }) => to)]),\n ]);\n const runner = phase.kind === 'working' ? resolveRunner(phaseId, phase) : undefined;\n const working = phase.kind === 'working' ? phase : undefined;\n if (working?.autoStart !== undefined && typeof working.autoStart !== 'boolean') {\n throw new BoardDefinitionError(`${label} autoStart must be a boolean.`);\n }\n const autoStartWhen = ruleGroup(working?.autoStartWhen, `${label} autoStartWhen`);\n if (autoStartWhen && working?.autoStart !== true) {\n throw new BoardDefinitionError(`${label} autoStartWhen needs autoStart.`);\n }\n const exitTool = resolveExitTool(phaseId, working?.exitTool);\n if (exitTool && nextPhases.length === 0) {\n throw new BoardDefinitionError(`${label} exit tool needs a next phase to move the card to.`);\n }\n const onEnter = runner ? phaseEnterHandlers(phase.onEnter, runner) : phase.onEnter;\n const name = resolveName(phase.name, phase.title, label);\n const description = optionalText(phase.description, `${label} description`, MAX_DESCRIPTION_LENGTH);\n return [\n phaseId,\n Object.freeze({\n name,\n title: name,\n ...(description !== undefined ? { description } : {}),\n kind: phase.kind,\n nextPhases,\n ...(phase.next !== undefined ? { next: phase.next } : {}),\n ...(phase.outcomes ? { outcomes: Object.freeze({ ...phase.outcomes }) } : {}),\n ...(runner ? { runner, role: runner.context } : {}),\n ...(working?.autoStart ? { autoStart: true } : {}),\n ...(autoStartWhen ? { autoStartWhen } : {}),\n ...(exitTool ? { exitTool } : {}),\n ...(onEnter ? { onEnter: Object.freeze({ ...onEnter }) } : {}),\n ...(phase.onExit ? { onExit: Object.freeze({ ...phase.onExit }) } : {}),\n }),\n ];\n }),\n ),\n ) as Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\n const rules = Object.freeze(\n Object.fromEntries(\n (Object.entries(phases) as [PhaseId, BoardPhase<PhaseId>][]).flatMap(([phaseId, phase]) => {\n const sources = new Set([...Object.keys(phase.onEnter ?? {}), ...Object.keys(phase.onExit ?? {})]);\n if (sources.size === 0) return [];\n return [\n [\n phaseId,\n Object.freeze(\n Object.fromEntries(\n [...sources].map(source => [\n source,\n Object.freeze({\n ...(phase.onEnter?.[source as FactoryRuleSource]\n ? { onEnter: phase.onEnter[source as FactoryRuleSource] }\n : {}),\n ...(phase.onExit?.[source as FactoryRuleSource]\n ? { onExit: phase.onExit[source as FactoryRuleSource] }\n : {}),\n }),\n ]),\n ),\n ),\n ],\n ];\n }),\n ),\n ) as ReadonlyFactoryBoardRules;\n\n const kinds = new Map<string, BoardPhaseKind>();\n const roles = new Map<string, string>();\n const phaseByRole = new Map<string, PhaseId>();\n for (const [phaseId, phase] of Object.entries(phases) as [PhaseId, BoardPhase<PhaseId>][]) {\n kinds.set(phaseId, phase.kind);\n if (phase.kind !== 'working') continue;\n roles.set(phaseId, phase.runner.context);\n if (!phaseByRole.has(phase.runner.context)) phaseByRole.set(phase.runner.context, phaseId);\n }\n\n const board = {\n id: config.id,\n name: boardName,\n title: boardName,\n ...(boardDescription !== undefined ? { description: boardDescription } : {}),\n initialPhase: config.initialPhase,\n phases,\n transitions: Object.freeze(transitions),\n rules: Object.freeze(rules),\n tools,\n events,\n ...(config.transitionPolicy ? { transitionPolicy: config.transitionPolicy } : {}),\n ...(sourceClosed ? { sourceClosed } : {}),\n allowsTransition(from: PhaseId, to: PhaseId) {\n return from === to || transitions[from]?.some(transition => transition.to === to) === true;\n },\n phaseKind: (phase: string) => kinds.get(phase),\n isWorking: (phase: string) => kinds.get(phase) === 'working',\n isTerminal: (phase: string) => kinds.get(phase) === 'terminal',\n roleForPhase: (phase: string) => roles.get(phase),\n phaseForRole: (role: string) => phaseByRole.get(role),\n startsAutomatically: (phase: string, facts?: RuleFacts) => {\n const definition = phases[phase as PhaseId] as BoardPhase<PhaseId> | undefined;\n if (definition?.kind !== 'working' || definition.autoStart !== true) return false;\n if (!definition.autoStartWhen) return true;\n return facts !== undefined && evaluateRuleGroup(definition.autoStartWhen, facts);\n },\n };\n if (defined) Object.defineProperty(board, DEFINED_BOARD, { value: true });\n Object.defineProperty(board, BOARD_DECLARATION, { value: config });\n if (codeBoard) Object.defineProperty(board, CODE_BOARD, { value: codeBoardOf(codeBoard) });\n return Object.freeze(board);\n}\n"],"mappings":";;;;;;AAoEA,MAAM,oBAAgF;CACpF,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,YAAY;AACd;;AA4BA,MAAa,mBAAmB;;AAGhC,MAAa,wBAAwB;AAuKrC,IAAa,uBAAb,cAA0C,MAAM;CAC9C,OAAgB;AAClB;AAEA,MAAM,8BAAmC,IAAI,IAAoB;CAAC;CAAW;CAAW;AAAU,CAAC;AAEnG,SAAS,wBAAwB,OAAgB,OAAqB;CACpE,IAAI,CAAC,kBAAkB,KAAK,GAC1B,MAAM,IAAI,qBAAqB,GAAG,MAAM,mCAAmC;AAE/E;AAEA,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;AAC/B,MAAM,0BAA0B;AAChC,MAAM,8BAAmC,IAAI,IAAI;CAAC;CAAW;CAAS;CAAW;AAAc,CAAC;AAChG,MAAM,iCAAsC,IAAI,IAAI;CAAC;CAAM;CAAe;AAAiB,CAAC;AAC5F,MAAM,sBAAsB;CAAC;CAAU;CAAa;CAAiB;AAAU;AAC/E,MAAM,YAAY;;AAGlB,SAAS,YAAY,MAAe,OAAgB,OAAuB;CACzE,IAAI,SAAS,KAAA,KAAa,UAAU,KAAA,KAAa,SAAS,OACxD,MAAM,IAAI,qBAAqB,GAAG,MAAM,sDAAsD;CAEhG,MA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C,WAAW,eAAe,OAAO;GACtC,OAAO,UAAU,KAAA,KAAa,kBAAkB,WAAW,eAAe,KAAK;EACjF;CACF;CACA,IAAI,SAAS,OAAO,eAAe,OAAO,eAAe,EAAE,OAAO,KAAK,CAAC;CACxE,OAAO,eAAe,OAAO,mBAAmB,EAAE,OAAO,OAAO,CAAC;CACjE,IAAI,WAAW,OAAO,eAAe,OAAO,YAAY,EAAE,OAAO,YAAY,SAAS,EAAE,CAAC;CACzF,OAAO,OAAO,OAAO,KAAK;AAC5B"}
@@ -1,10 +1,14 @@
1
1
  import type { RuleFacts } from '../rules/rule-group.js';
2
2
  import type { StoredBoardsStorage, StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';
3
3
  import type { Card } from '../storage/domains/work-items/base.js';
4
+ import type { BoardEventFacts } from './board-events.js';
4
5
  import type { BoardRegistry, InstalledBoard } from './registry.js';
5
6
  /** Reads a project's intake routes, in order. */
6
7
  export type IntakeRoutesReader = Pick<StoredBoardsStorage, 'listIntakeRoutes'>;
7
- type IntakeRoute = Pick<StoredIntakeRouteRecord, 'id' | 'enabled' | 'when' | 'target'>;
8
+ type IntakeRoute = Pick<StoredIntakeRouteRecord, 'id' | 'enabled' | 'when' | 'target' | 'on'>;
9
+ type EventRoute = IntakeRoute & Pick<StoredIntakeRouteRecord, 'allowWorkingPhase'>;
10
+ /** Whether the route places new cards, rather than only moving existing ones on later events. */
11
+ export declare function placesNewCards(route: Pick<StoredIntakeRouteRecord, 'on'>): boolean;
8
12
  /**
9
13
  * Card metadata naming the intake route that placed the card. Label routes, repository
10
14
  * bindings and replayed arrivals leave such a card where the route put it.
@@ -16,13 +20,20 @@ export type IntakeTargetProblem = {
16
20
  code: 'unknown_board' | 'unknown_phase' | 'terminal_phase' | 'unreachable_phase';
17
21
  message: string;
18
22
  };
19
- /** Why a route's target can't take cards in this project, or undefined when it can. */
20
- export declare function intakeTargetProblem(registry: BoardRegistry, target: {
21
- boardKey: string;
22
- phaseKey?: string | null;
23
+ /**
24
+ * Why a route's target can't take cards in this project, or undefined when it can. A route that
25
+ * places new cards needs a phase they can reach; one that only moves existing cards on later
26
+ * events, such as a close, may name any phase, terminal ones included.
27
+ */
28
+ export declare function intakeTargetProblem(registry: BoardRegistry, route: {
29
+ target: {
30
+ boardKey: string;
31
+ phaseKey?: string | null;
32
+ };
33
+ on: readonly string[];
23
34
  }): IntakeTargetProblem | undefined;
24
35
  /**
25
- * Where a new card lands: the first enabled route whose condition matches the card and whose
36
+ * Where a new card lands: the first enabled route that places new cards, whose condition matches the card and whose
26
37
  * board is installed and can hold it. A route without a phase, or whose phase has since gone,
27
38
  * lands the card in the board's initial phase. Undefined leaves today's placement alone.
28
39
  */
@@ -33,5 +44,18 @@ export declare function resolveIntakePlacement(routes: readonly IntakeRoute[], f
33
44
  } | undefined;
34
45
  /** The phase a route's card lands in: its named phase when new cards can reach it, else the board's first. */
35
46
  export declare function landingPhase(board: InstalledBoard, phase: string | null | undefined): string;
47
+ /** Whether any route on the board, enabled or not, handles the event: then the routes own it. */
48
+ export declare function routesHandleEvent(routes: readonly Pick<IntakeRoute, 'on' | 'target'>[], event: BoardEventFacts, board: Pick<InstalledBoard, 'id'>): boolean;
49
+ /**
50
+ * Where a status event moves an existing card: the first enabled route whose `on` names the
51
+ * event, whose `when` matches the card and the event, and whose board is the card's own and can
52
+ * hold it there. A route without a phase moves the card to its board's first phase. Undefined
53
+ * leaves the card where it is.
54
+ */
55
+ export declare function resolveEventRoute(routes: readonly EventRoute[], event: BoardEventFacts, cardFacts: RuleFacts, board: InstalledBoard): {
56
+ phase: string;
57
+ routeId: string;
58
+ allowWorkingPhase: boolean;
59
+ } | undefined;
36
60
  export {};
37
61
  //# sourceMappingURL=intake-routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"intake-routing.d.ts","sourceRoot":"","sources":["../../src/boards/intake-routing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAA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AAE,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAAC,EAAE,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACvF,mBAAmB,GAAG,SAAS,CAyBjC;AAcD;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,aAAa,GACtB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAU/D;AAED,8GAA8G;AAC9G,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAO5F;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,QAAQ,CAAC,EAAE,EACrD,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,GAChC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,cAAc,GACpB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAc5E"}
@@ -1,5 +1,9 @@
1
1
  import { evaluateRuleGroup } from "../rules/rule-group.js";
2
2
  // src/boards/intake-routing.ts
3
+ /** Whether the route places new cards, rather than only moving existing ones on later events. */
4
+ function placesNewCards(route) {
5
+ return route.on.includes("work_item.created");
6
+ }
3
7
  /**
4
8
  * Card metadata naming the intake route that placed the card. Label routes, repository
5
9
  * bindings and replayed arrivals leave such a card where the route put it.
@@ -9,8 +13,13 @@ const INTAKE_ROUTE_METADATA_KEY = "intakeRouteId";
9
13
  function placedByIntakeRoute(item) {
10
14
  return typeof item.metadata?.[INTAKE_ROUTE_METADATA_KEY] === "string";
11
15
  }
12
- /** Why a route's target can't take cards in this project, or undefined when it can. */
13
- function intakeTargetProblem(registry, target) {
16
+ /**
17
+ * Why a route's target can't take cards in this project, or undefined when it can. A route that
18
+ * places new cards needs a phase they can reach; one that only moves existing cards on later
19
+ * events, such as a close, may name any phase, terminal ones included.
20
+ */
21
+ function intakeTargetProblem(registry, route) {
22
+ const { target } = route;
14
23
  const board = registry.get(target.boardKey);
15
24
  if (!board) return {
16
25
  code: "unknown_board",
@@ -22,6 +31,7 @@ function intakeTargetProblem(registry, target) {
22
31
  code: "unknown_phase",
23
32
  message: `Board "${target.boardKey}" has no phase "${target.phaseKey}".`
24
33
  };
34
+ if (!route.on.includes("work_item.created")) return void 0;
25
35
  if (kind === "terminal") return {
26
36
  code: "terminal_phase",
27
37
  message: `Phase "${target.phaseKey}" on board "${target.boardKey}" is terminal; new cards can't land there.`
@@ -43,13 +53,13 @@ function placementTakesCard(boardId, phase, facts) {
43
53
  return true;
44
54
  }
45
55
  /**
46
- * Where a new card lands: the first enabled route whose condition matches the card and whose
56
+ * Where a new card lands: the first enabled route that places new cards, whose condition matches the card and whose
47
57
  * board is installed and can hold it. A route without a phase, or whose phase has since gone,
48
58
  * lands the card in the board's initial phase. Undefined leaves today's placement alone.
49
59
  */
50
60
  function resolveIntakePlacement(routes, facts, registry) {
51
61
  for (const route of routes) {
52
- if (!route.enabled || !evaluateRuleGroup(route.when, facts)) continue;
62
+ if (!route.enabled || !placesNewCards(route) || !evaluateRuleGroup(route.when, facts)) continue;
53
63
  const board = registry.get(route.target.boardKey);
54
64
  if (!board) continue;
55
65
  const phase = landingPhase(board, route.target.phaseKey);
@@ -65,6 +75,34 @@ function resolveIntakePlacement(routes, facts, registry) {
65
75
  function landingPhase(board, phase) {
66
76
  return phase && board.phaseKind(phase) !== void 0 && !board.isTerminal(phase) && board.allowsTransition(board.initialPhase, phase) ? phase : board.initialPhase;
67
77
  }
68
- export { INTAKE_ROUTE_METADATA_KEY, intakeTargetProblem, landingPhase, placedByIntakeRoute, resolveIntakePlacement };
78
+ /** Whether any route on the board, enabled or not, handles the event: then the routes own it. */
79
+ function routesHandleEvent(routes, event, board) {
80
+ return routes.some((route) => route.target.boardKey === board.id && route.on.includes(event.type));
81
+ }
82
+ /**
83
+ * Where a status event moves an existing card: the first enabled route whose `on` names the
84
+ * event, whose `when` matches the card and the event, and whose board is the card's own and can
85
+ * hold it there. A route without a phase moves the card to its board's first phase. Undefined
86
+ * leaves the card where it is.
87
+ */
88
+ function resolveEventRoute(routes, event, cardFacts, board) {
89
+ const facts = {
90
+ ...cardFacts,
91
+ "event.type": event.type,
92
+ ...event.reason ? { "event.reason": event.reason } : {}
93
+ };
94
+ for (const route of routes) {
95
+ if (!route.enabled || !route.on.includes(event.type) || route.target.boardKey !== board.id) continue;
96
+ if (!evaluateRuleGroup(route.when, facts)) continue;
97
+ const phase = route.target.phaseKey ?? board.initialPhase;
98
+ if (board.phaseKind(phase) === void 0 || !placementTakesCard(board.id, phase, facts)) continue;
99
+ return {
100
+ phase,
101
+ routeId: route.id,
102
+ allowWorkingPhase: route.allowWorkingPhase
103
+ };
104
+ }
105
+ }
106
+ export { INTAKE_ROUTE_METADATA_KEY, intakeTargetProblem, landingPhase, placedByIntakeRoute, placesNewCards, resolveEventRoute, resolveIntakePlacement, routesHandleEvent };
69
107
 
70
108
  //# sourceMappingURL=intake-routing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"intake-routing.js","names":[],"sources":["../../src/boards/intake-routing.ts"],"sourcesContent":["import { evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { RuleFacts } from '../rules/rule-group.js';\nimport type { StoredBoardsStorage, StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport type { BoardRegistry, InstalledBoard } from './registry.js';\n\n/** Reads a project's intake routes, in order. */\nexport type IntakeRoutesReader = Pick<StoredBoardsStorage, 'listIntakeRoutes'>;\n\ntype IntakeRoute = Pick<StoredIntakeRouteRecord, 'id' | 'enabled' | 'when' | 'target'>;\n\n/**\n * Card metadata naming the intake route that placed the card. Label routes, repository\n * bindings and replayed arrivals leave such a card where the route put it.\n */\nexport const INTAKE_ROUTE_METADATA_KEY = 'intakeRouteId';\n\n/** Whether an intake route chose this card's board when it arrived. */\nexport function placedByIntakeRoute(item: Pick<Card, 'metadata'>): boolean {\n return typeof item.metadata?.[INTAKE_ROUTE_METADATA_KEY] === 'string';\n}\n\nexport type IntakeTargetProblem = {\n code: 'unknown_board' | 'unknown_phase' | 'terminal_phase' | 'unreachable_phase';\n message: string;\n};\n\n/** Why a route's target can't take cards in this project, or undefined when it can. */\nexport function intakeTargetProblem(\n registry: BoardRegistry,\n target: { boardKey: string; phaseKey?: string | null },\n): IntakeTargetProblem | undefined {\n const board = registry.get(target.boardKey);\n if (!board) {\n return { code: 'unknown_board', message: `Board \"${target.boardKey}\" is not installed in this project.` };\n }\n if (!target.phaseKey) return undefined;\n const kind = board.phaseKind(target.phaseKey);\n if (!kind) {\n return { code: 'unknown_phase', message: `Board \"${target.boardKey}\" has no phase \"${target.phaseKey}\".` };\n }\n if (kind === 'terminal') {\n return {\n code: 'terminal_phase',\n message: `Phase \"${target.phaseKey}\" on board \"${target.boardKey}\" is terminal; new cards can't land there.`,\n };\n }\n if (!board.allowsTransition(board.initialPhase, target.phaseKey)) {\n return {\n code: 'unreachable_phase',\n message: `Board \"${target.boardKey}\" doesn't allow moving a card from its first phase \"${board.initialPhase}\" to \"${target.phaseKey}\".`,\n };\n }\n return undefined;\n}\n\n/**\n * The built-in Review board holds only pull requests. On Work a new pull request card lands in\n * Intake or PR review, and nothing else lands in PR review. `FactoryTransitionService` refuses\n * any move that breaks this, so a route can't either.\n */\nfunction placementTakesCard(boardId: string, phase: string, facts: RuleFacts): boolean {\n const pullRequest = facts['source.kind'] === 'pull_request';\n if (boardId === 'review') return pullRequest;\n if (boardId === 'work') return pullRequest ? phase === 'intake' || phase === 'pr-review' : phase !== 'pr-review';\n return true;\n}\n\n/**\n * Where a new card lands: the first enabled route whose condition matches the card and whose\n * board is installed and can hold it. A route without a phase, or whose phase has since gone,\n * lands the card in the board's initial phase. Undefined leaves today's placement alone.\n */\nexport function resolveIntakePlacement(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n): { board: string; phase: string; routeId: string } | undefined {\n for (const route of routes) {\n if (!route.enabled || !evaluateRuleGroup(route.when, facts)) continue;\n const board = registry.get(route.target.boardKey);\n if (!board) continue;\n const phase = landingPhase(board, route.target.phaseKey);\n if (!placementTakesCard(board.id, phase, facts)) continue;\n return { board: board.id, phase, routeId: route.id };\n }\n return undefined;\n}\n\n/** The phase a route's card lands in: its named phase when new cards can reach it, else the board's first. */\nexport function landingPhase(board: InstalledBoard, phase: string | null | undefined): string {\n const usable =\n phase &&\n board.phaseKind(phase) !== undefined &&\n !board.isTerminal(phase) &&\n board.allowsTransition(board.initialPhase, phase);\n return usable ? phase : board.initialPhase;\n}\n"],"mappings":";;;;;;AAeA,MAAa,4BAA4B;;AAGzC,SAAgB,oBAAoB,MAAuC;CACzE,OAAO,OAAO,KAAK,WAAW,+BAA+B;AAC/D;;AAQA,SAAgB,oBACd,UACA,QACiC;CACjC,MAAM,QAAQ,SAAS,IAAI,OAAO,QAAQ;CAC1C,IAAI,CAAC,OACH,OAAO;EAAE,MAAM;EAAiB,SAAS,UAAU,OAAO,SAAS;CAAqC;CAE1G,IAAI,CAAC,OAAO,UAAU,OAAO,KAAA;CAC7B,MAAM,OAAO,MAAM,UAAU,OAAO,QAAQ;CAC5C,IAAI,CAAC,MACH,OAAO;EAAE,MAAM;EAAiB,SAAS,UAAU,OAAO,SAAS,kBAAkB,OAAO,SAAS;CAAI;CAE3G,IAAI,SAAS,YACX,OAAO;EACL,MAAM;EACN,SAAS,UAAU,OAAO,SAAS,cAAc,OAAO,SAAS;CACnE;CAEF,IAAI,CAAC,MAAM,iBAAiB,MAAM,cAAc,OAAO,QAAQ,GAC7D,OAAO;EACL,MAAM;EACN,SAAS,UAAU,OAAO,SAAS,sDAAsD,MAAM,aAAa,QAAQ,OAAO,SAAS;CACtI;AAGJ;;;;;;AAOA,SAAS,mBAAmB,SAAiB,OAAe,OAA2B;CACrF,MAAM,cAAc,MAAM,mBAAmB;CAC7C,IAAI,YAAY,UAAU,OAAO;CACjC,IAAI,YAAY,QAAQ,OAAO,cAAc,UAAU,YAAY,UAAU,cAAc,UAAU;CACrG,OAAO;AACT;;;;;;AAOA,SAAgB,uBACd,QACA,OACA,UAC+D;CAC/D,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,WAAW,CAAC,kBAAkB,MAAM,MAAM,KAAK,GAAG;EAC7D,MAAM,QAAQ,SAAS,IAAI,MAAM,OAAO,QAAQ;EAChD,IAAI,CAAC,OAAO;EACZ,MAAM,QAAQ,aAAa,OAAO,MAAM,OAAO,QAAQ;EACvD,IAAI,CAAC,mBAAmB,MAAM,IAAI,OAAO,KAAK,GAAG;EACjD,OAAO;GAAE,OAAO,MAAM;GAAI;GAAO,SAAS,MAAM;EAAG;CACrD;AAEF;;AAGA,SAAgB,aAAa,OAAuB,OAA0C;CAM5F,OAJE,SACA,MAAM,UAAU,KAAK,MAAM,KAAA,KAC3B,CAAC,MAAM,WAAW,KAAK,KACvB,MAAM,iBAAiB,MAAM,cAAc,KAAK,IAClC,QAAQ,MAAM;AAChC"}
1
+ {"version":3,"file":"intake-routing.js","names":[],"sources":["../../src/boards/intake-routing.ts"],"sourcesContent":["import { evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { RuleFacts } from '../rules/rule-group.js';\nimport type { StoredBoardsStorage, StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport type { BoardEventFacts } from './board-events.js';\nimport type { BoardRegistry, InstalledBoard } from './registry.js';\n\n/** Reads a project's intake routes, in order. */\nexport type IntakeRoutesReader = Pick<StoredBoardsStorage, 'listIntakeRoutes'>;\n\ntype IntakeRoute = Pick<StoredIntakeRouteRecord, 'id' | 'enabled' | 'when' | 'target' | 'on'>;\ntype EventRoute = IntakeRoute & Pick<StoredIntakeRouteRecord, 'allowWorkingPhase'>;\n\n/** Whether the route places new cards, rather than only moving existing ones on later events. */\nexport function placesNewCards(route: Pick<StoredIntakeRouteRecord, 'on'>): boolean {\n return route.on.includes('work_item.created');\n}\n\n/**\n * Card metadata naming the intake route that placed the card. Label routes, repository\n * bindings and replayed arrivals leave such a card where the route put it.\n */\nexport const INTAKE_ROUTE_METADATA_KEY = 'intakeRouteId';\n\n/** Whether an intake route chose this card's board when it arrived. */\nexport function placedByIntakeRoute(item: Pick<Card, 'metadata'>): boolean {\n return typeof item.metadata?.[INTAKE_ROUTE_METADATA_KEY] === 'string';\n}\n\nexport type IntakeTargetProblem = {\n code: 'unknown_board' | 'unknown_phase' | 'terminal_phase' | 'unreachable_phase';\n message: string;\n};\n\n/**\n * Why a route's target can't take cards in this project, or undefined when it can. A route that\n * places new cards needs a phase they can reach; one that only moves existing cards on later\n * events, such as a close, may name any phase, terminal ones included.\n */\nexport function intakeTargetProblem(\n registry: BoardRegistry,\n route: { target: { boardKey: string; phaseKey?: string | null }; on: readonly string[] },\n): IntakeTargetProblem | undefined {\n const { target } = route;\n const board = registry.get(target.boardKey);\n if (!board) {\n return { code: 'unknown_board', message: `Board \"${target.boardKey}\" is not installed in this project.` };\n }\n if (!target.phaseKey) return undefined;\n const kind = board.phaseKind(target.phaseKey);\n if (!kind) {\n return { code: 'unknown_phase', message: `Board \"${target.boardKey}\" has no phase \"${target.phaseKey}\".` };\n }\n if (!route.on.includes('work_item.created')) return undefined;\n if (kind === 'terminal') {\n return {\n code: 'terminal_phase',\n message: `Phase \"${target.phaseKey}\" on board \"${target.boardKey}\" is terminal; new cards can't land there.`,\n };\n }\n if (!board.allowsTransition(board.initialPhase, target.phaseKey)) {\n return {\n code: 'unreachable_phase',\n message: `Board \"${target.boardKey}\" doesn't allow moving a card from its first phase \"${board.initialPhase}\" to \"${target.phaseKey}\".`,\n };\n }\n return undefined;\n}\n\n/**\n * The built-in Review board holds only pull requests. On Work a new pull request card lands in\n * Intake or PR review, and nothing else lands in PR review. `FactoryTransitionService` refuses\n * any move that breaks this, so a route can't either.\n */\nfunction placementTakesCard(boardId: string, phase: string, facts: RuleFacts): boolean {\n const pullRequest = facts['source.kind'] === 'pull_request';\n if (boardId === 'review') return pullRequest;\n if (boardId === 'work') return pullRequest ? phase === 'intake' || phase === 'pr-review' : phase !== 'pr-review';\n return true;\n}\n\n/**\n * Where a new card lands: the first enabled route that places new cards, whose condition matches the card and whose\n * board is installed and can hold it. A route without a phase, or whose phase has since gone,\n * lands the card in the board's initial phase. Undefined leaves today's placement alone.\n */\nexport function resolveIntakePlacement(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n): { board: string; phase: string; routeId: string } | undefined {\n for (const route of routes) {\n if (!route.enabled || !placesNewCards(route) || !evaluateRuleGroup(route.when, facts)) continue;\n const board = registry.get(route.target.boardKey);\n if (!board) continue;\n const phase = landingPhase(board, route.target.phaseKey);\n if (!placementTakesCard(board.id, phase, facts)) continue;\n return { board: board.id, phase, routeId: route.id };\n }\n return undefined;\n}\n\n/** The phase a route's card lands in: its named phase when new cards can reach it, else the board's first. */\nexport function landingPhase(board: InstalledBoard, phase: string | null | undefined): string {\n const usable =\n phase &&\n board.phaseKind(phase) !== undefined &&\n !board.isTerminal(phase) &&\n board.allowsTransition(board.initialPhase, phase);\n return usable ? phase : board.initialPhase;\n}\n\n/** Whether any route on the board, enabled or not, handles the event: then the routes own it. */\nexport function routesHandleEvent(\n routes: readonly Pick<IntakeRoute, 'on' | 'target'>[],\n event: BoardEventFacts,\n board: Pick<InstalledBoard, 'id'>,\n): boolean {\n return routes.some(route => route.target.boardKey === board.id && route.on.includes(event.type));\n}\n\n/**\n * Where a status event moves an existing card: the first enabled route whose `on` names the\n * event, whose `when` matches the card and the event, and whose board is the card's own and can\n * hold it there. A route without a phase moves the card to its board's first phase. Undefined\n * leaves the card where it is.\n */\nexport function resolveEventRoute(\n routes: readonly EventRoute[],\n event: BoardEventFacts,\n cardFacts: RuleFacts,\n board: InstalledBoard,\n): { phase: string; routeId: string; allowWorkingPhase: boolean } | undefined {\n const facts: RuleFacts = {\n ...cardFacts,\n 'event.type': event.type,\n ...(event.reason ? { 'event.reason': event.reason } : {}),\n };\n for (const route of routes) {\n if (!route.enabled || !route.on.includes(event.type) || route.target.boardKey !== board.id) continue;\n if (!evaluateRuleGroup(route.when, facts)) continue;\n const phase = route.target.phaseKey ?? board.initialPhase;\n if (board.phaseKind(phase) === undefined || !placementTakesCard(board.id, phase, facts)) continue;\n return { phase, routeId: route.id, allowWorkingPhase: route.allowWorkingPhase };\n }\n return undefined;\n}\n"],"mappings":";;;AAcA,SAAgB,eAAe,OAAqD;CAClF,OAAO,MAAM,GAAG,SAAS,mBAAmB;AAC9C;;;;;AAMA,MAAa,4BAA4B;;AAGzC,SAAgB,oBAAoB,MAAuC;CACzE,OAAO,OAAO,KAAK,WAAW,+BAA+B;AAC/D;;;;;;AAYA,SAAgB,oBACd,UACA,OACiC;CACjC,MAAM,EAAE,WAAW;CACnB,MAAM,QAAQ,SAAS,IAAI,OAAO,QAAQ;CAC1C,IAAI,CAAC,OACH,OAAO;EAAE,MAAM;EAAiB,SAAS,UAAU,OAAO,SAAS;CAAqC;CAE1G,IAAI,CAAC,OAAO,UAAU,OAAO,KAAA;CAC7B,MAAM,OAAO,MAAM,UAAU,OAAO,QAAQ;CAC5C,IAAI,CAAC,MACH,OAAO;EAAE,MAAM;EAAiB,SAAS,UAAU,OAAO,SAAS,kBAAkB,OAA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,CAAC,GAAG,OAAO,CAE7G"}
1
+ {"version":3,"file":"legacy-plan-role.d.ts","sourceRoot":"","sources":["../../src/boards/legacy-plan-role.ts"],"names":[],"mappings":"AAwBA,8GAA8G;AAC9G,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEhF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAMrH;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEnF;AAED,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAE7G"}
@@ -1,10 +1,14 @@
1
1
  import { factoryLaneForRole } from "../rules/types.js";
2
+ import { codeBoardOf } from "./define-board.js";
2
3
  import { workBoard } from "./work.js";
3
4
  // src/boards/legacy-plan-role.ts
4
5
  const LEGACY_PLAN_ROLE = "plan";
6
+ function isWorkBoard(board) {
7
+ return typeof board === "object" && board !== null && codeBoardOf(board) === workBoard;
8
+ }
5
9
  /** The built-in Work lane a role's run belongs to: `plan` plans, `work` builds. Undefined on other boards. */
6
10
  function workLaneForRole(board, role) {
7
- return board === workBoard ? factoryLaneForRole(role) : void 0;
11
+ return isWorkBoard(board) ? factoryLaneForRole(role) : void 0;
8
12
  }
9
13
  /**
10
14
  * Whether a built-in Work stage carries a run decided for `role`. Planning,
@@ -13,10 +17,10 @@ function workLaneForRole(board, role) {
13
17
  * Building and Review the other `work` runs. Undefined on other boards.
14
18
  */
15
19
  function workStageCarries(board, stage, role, skillName) {
16
- if (board !== workBoard) return void 0;
20
+ if (!isWorkBoard(board)) return void 0;
17
21
  if (role === LEGACY_PLAN_ROLE) return stage === "planning";
18
- if (role !== "work") return workBoard.roleForPhase(stage) === role;
19
- if (workBoard.roleForPhase(stage) !== "work") return false;
22
+ if (role !== "work") return board.roleForPhase(stage) === role;
23
+ if (board.roleForPhase(stage) !== "work") return false;
20
24
  return stage === "planning" === (skillName === "factory-plan");
21
25
  }
22
26
  /** The session key a Work build falls back to when the card has no `work` session yet. */
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-plan-role.js","names":[],"sources":["../../src/boards/legacy-plan-role.ts"],"sourcesContent":["import { factoryLaneForRole } from '../rules/types.js';\nimport { workBoard } from './work.js';\n\n/*\n * Compatibility for the Work board's old `plan` role. Planning moved into the\n * `work` context, so Work's lanes no longer follow from its contexts alone, and\n * cards planned before the move hold their planner under `plan`. Delete these\n * once no card holds a `plan` session and no queued decision names `plan`.\n */\n\nconst LEGACY_PLAN_ROLE = 'plan';\n\n/*\n * Only the built-in Work board gets these rules. A board installed as `work` in\n * place of it is matched by its own contexts, like any other board.\n */\n\n/** The built-in Work lane a role's run belongs to: `plan` plans, `work` builds. Undefined on other boards. */\nexport function workLaneForRole(board: unknown, role: string): string | undefined {\n return board === workBoard ? factoryLaneForRole(role) : undefined;\n}\n\n/**\n * Whether a built-in Work stage carries a run decided for `role`. Planning,\n * Building and Review share the `work` context, so the skill tells them apart:\n * Planning carries `factory-plan` runs (and runs for the old `plan` role),\n * Building and Review the other `work` runs. Undefined on other boards.\n */\nexport function workStageCarries(board: unknown, stage: string, role: string, skillName: unknown): boolean | undefined {\n if (board !== workBoard) return undefined;\n if (role === LEGACY_PLAN_ROLE) return stage === 'planning';\n if (role !== 'work') return workBoard.roleForPhase(stage) === role;\n if (workBoard.roleForPhase(stage) !== 'work') return false;\n return (stage === 'planning') === (skillName === 'factory-plan');\n}\n\n/** The session key a Work build falls back to when the card has no `work` session yet. */\nexport function legacyPlanRoleFor(boardId: string, role: string): string | undefined {\n return boardId === 'work' && role === 'work' ? LEGACY_PLAN_ROLE : undefined;\n}\n\n/** Whether a Work card in Planning still holds its planner under the old `plan` key. */\nexport function holdsLegacyPlanner(boardId: string, stage: string, sessions: Record<string, unknown>): boolean {\n return boardId === 'work' && stage === 'planning' && sessions[LEGACY_PLAN_ROLE] !== undefined;\n}\n"],"mappings":";;;AAUA,MAAM,mBAAmB;;AAQzB,SAAgB,gBAAgB,OAAgB,MAAkC;CAChF,OAAO,UAAU,YAAY,mBAAmB,IAAI,IAAI,KAAA;AAC1D;;;;;;;AAQA,SAAgB,iBAAiB,OAAgB,OAAe,MAAc,WAAyC;CACrH,IAAI,UAAU,WAAW,OAAO,KAAA;CAChC,IAAI,SAAS,kBAAkB,OAAO,UAAU;CAChD,IAAI,SAAS,QAAQ,OAAO,UAAU,aAAa,KAAK,MAAM;CAC9D,IAAI,UAAU,aAAa,KAAK,MAAM,QAAQ,OAAO;CACrD,OAAQ,UAAU,gBAAiB,cAAc;AACnD;;AAGA,SAAgB,kBAAkB,SAAiB,MAAkC;CACnF,OAAO,YAAY,UAAU,SAAS,SAAS,mBAAmB,KAAA;AACpE;;AAGA,SAAgB,mBAAmB,SAAiB,OAAe,UAA4C;CAC7G,OAAO,YAAY,UAAU,UAAU,cAAc,SAAS,sBAAsB,KAAA;AACtF"}
1
+ {"version":3,"file":"legacy-plan-role.js","names":[],"sources":["../../src/boards/legacy-plan-role.ts"],"sourcesContent":["import { factoryLaneForRole } from '../rules/types.js';\nimport { codeBoardOf } from './define-board.js';\nimport type { InstalledBoard } from './registry.js';\nimport { workBoard } from './work.js';\n\n/*\n * Compatibility for the Work board's old `plan` role. Planning moved into the\n * `work` context, so Work's lanes no longer follow from its contexts alone, and\n * cards planned before the move hold their planner under `plan`. Delete these\n * once no card holds a `plan` session and no queued decision names `plan`.\n */\n\nconst LEGACY_PLAN_ROLE = 'plan';\n\n/*\n * Only the built-in Work board, as code defines it or as a project edited it, gets\n * these rules. A board installed as `work` in place of it is matched by its own\n * contexts, like any other board.\n */\n\nfunction isWorkBoard(board: unknown): board is InstalledBoard {\n return typeof board === 'object' && board !== null && codeBoardOf(board) === workBoard;\n}\n\n/** The built-in Work lane a role's run belongs to: `plan` plans, `work` builds. Undefined on other boards. */\nexport function workLaneForRole(board: unknown, role: string): string | undefined {\n return isWorkBoard(board) ? factoryLaneForRole(role) : undefined;\n}\n\n/**\n * Whether a built-in Work stage carries a run decided for `role`. Planning,\n * Building and Review share the `work` context, so the skill tells them apart:\n * Planning carries `factory-plan` runs (and runs for the old `plan` role),\n * Building and Review the other `work` runs. Undefined on other boards.\n */\nexport function workStageCarries(board: unknown, stage: string, role: string, skillName: unknown): boolean | undefined {\n if (!isWorkBoard(board)) return undefined;\n if (role === LEGACY_PLAN_ROLE) return stage === 'planning';\n if (role !== 'work') return board.roleForPhase(stage) === role;\n if (board.roleForPhase(stage) !== 'work') return false;\n return (stage === 'planning') === (skillName === 'factory-plan');\n}\n\n/** The session key a Work build falls back to when the card has no `work` session yet. */\nexport function legacyPlanRoleFor(boardId: string, role: string): string | undefined {\n return boardId === 'work' && role === 'work' ? LEGACY_PLAN_ROLE : undefined;\n}\n\n/** Whether a Work card in Planning still holds its planner under the old `plan` key. */\nexport function holdsLegacyPlanner(boardId: string, stage: string, sessions: Record<string, unknown>): boolean {\n return boardId === 'work' && stage === 'planning' && sessions[LEGACY_PLAN_ROLE] !== undefined;\n}\n"],"mappings":";;;;AAYA,MAAM,mBAAmB;AAQzB,SAAS,YAAY,OAAyC;CAC5D,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY,KAAK,MAAM;AAC/E;;AAGA,SAAgB,gBAAgB,OAAgB,MAAkC;CAChF,OAAO,YAAY,KAAK,IAAI,mBAAmB,IAAI,IAAI,KAAA;AACzD;;;;;;;AAQA,SAAgB,iBAAiB,OAAgB,OAAe,MAAc,WAAyC;CACrH,IAAI,CAAC,YAAY,KAAK,GAAG,OAAO,KAAA;CAChC,IAAI,SAAS,kBAAkB,OAAO,UAAU;CAChD,IAAI,SAAS,QAAQ,OAAO,MAAM,aAAa,KAAK,MAAM;CAC1D,IAAI,MAAM,aAAa,KAAK,MAAM,QAAQ,OAAO;CACjD,OAAQ,UAAU,gBAAiB,cAAc;AACnD;;AAGA,SAAgB,kBAAkB,SAAiB,MAAkC;CACnF,OAAO,YAAY,UAAU,SAAS,SAAS,mBAAmB,KAAA;AACpE;;AAGA,SAAgB,mBAAmB,SAAiB,OAAe,UAA4C;CAC7G,OAAO,YAAY,UAAU,UAAU,cAAc,SAAS,sBAAsB,KAAA;AACtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"phase-automation.d.ts","sourceRoot":"","sources":["../../src/boards/phase-automation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,KAAK,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;AAEvG;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAQlH;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAK/F"}
1
+ {"version":3,"file":"phase-automation.d.ts","sourceRoot":"","sources":["../../src/boards/phase-automation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAGlE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,KAAK,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;AAEvG;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAclH;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAK/F"}
@@ -1,6 +1,8 @@
1
1
  import { evaluateRuleGroup } from "../rules/rule-group.js";
2
2
  import { cardRuleFacts } from "./card-facts.js";
3
+ import { codeBoardOf } from "./define-board.js";
3
4
  import { boardForWorkItem } from "./semantics.js";
5
+ import { workBoard } from "./work.js";
4
6
  // src/boards/phase-automation.ts
5
7
  /**
6
8
  * Whether the decision starts the run of a phase that starts on its own for this card
@@ -9,9 +11,12 @@ import { boardForWorkItem } from "./semantics.js";
9
11
  function startsInAutoPhase(boards, item, decision) {
10
12
  if (decision.type === "transition") return boards.get(decision.board)?.startsAutomatically(decision.stage, cardRuleFacts(item)) === true;
11
13
  if (decision.type !== "invokeSkill" || item.stages.length !== 1) return false;
12
- const board = boards.get(boardForWorkItem(item));
14
+ const boardKey = boardForWorkItem(item);
15
+ const board = boards.get(boardKey);
13
16
  const stage = item.stages[0];
14
- return board?.roleForPhase(stage) === decision.role && board.startsAutomatically(stage, cardRuleFacts(item));
17
+ if (!board) return false;
18
+ const reviewerSeat = decision.role === "review" && codeBoardOf(board) === workBoard && (stage === "review" || stage === "pr-review");
19
+ return (board.roleForPhase(stage) === decision.role || reviewerSeat) && board.startsAutomatically(stage, cardRuleFacts(item));
15
20
  }
16
21
  /** The exit tool of the card's phase when it is approved without a person for this card. */
17
22
  function autoApprovedExitTool(boards, item) {
@@ -1 +1 @@
1
- {"version":3,"file":"phase-automation.js","names":[],"sources":["../../src/boards/phase-automation.ts"],"sourcesContent":["import { evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { FactoryCommitDecision } from '../rules/types.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport { cardRuleFacts } from './card-facts.js';\nimport type { BoardRegistry } from './registry.js';\nimport { boardForWorkItem } from './semantics.js';\n\ntype PhaseCard = Pick<Card, 'board' | 'externalSource' | 'stages' | 'title' | 'metadata' | 'workItem'>;\n\n/**\n * Whether the decision starts the run of a phase that starts on its own for this card\n * (`autoStart`, and `autoStartWhen` when set), so it needs nobody's approval.\n */\nexport function startsInAutoPhase(boards: BoardRegistry, item: PhaseCard, decision: FactoryCommitDecision): boolean {\n if (decision.type === 'transition') {\n return boards.get(decision.board)?.startsAutomatically(decision.stage, cardRuleFacts(item)) === true;\n }\n if (decision.type !== 'invokeSkill' || item.stages.length !== 1) return false;\n const board = boards.get(boardForWorkItem(item));\n const stage = item.stages[0]!;\n return board?.roleForPhase(stage) === decision.role && board.startsAutomatically(stage, cardRuleFacts(item));\n}\n\n/** The exit tool of the card's phase when it is approved without a person for this card. */\nexport function autoApprovedExitTool(boards: BoardRegistry, item: PhaseCard): string | undefined {\n if (item.stages.length !== 1) return undefined;\n const phase = boards.get(boardForWorkItem(item))?.phases[item.stages[0]!];\n if (phase?.kind !== 'working' || !phase.exitTool?.autoApprove) return undefined;\n return evaluateRuleGroup(phase.exitTool.autoApproveWhen, cardRuleFacts(item)) ? phase.exitTool.id : undefined;\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,kBAAkB,QAAuB,MAAiB,UAA0C;CAClH,IAAI,SAAS,SAAS,cACpB,OAAO,OAAO,IAAI,SAAS,KAAK,CAAC,EAAE,oBAAoB,SAAS,OAAO,cAAc,IAAI,CAAC,MAAM;CAElG,IAAI,SAAS,SAAS,iBAAiB,KAAK,OAAO,WAAW,GAAG,OAAO;CACxE,MAAM,QAAQ,OAAO,IAAI,iBAAiB,IAAI,CAAC;CAC/C,MAAM,QAAQ,KAAK,OAAO;CAC1B,OAAO,OAAO,aAAa,KAAK,MAAM,SAAS,QAAQ,MAAM,oBAAoB,OAAO,cAAc,IAAI,CAAC;AAC7G;;AAGA,SAAgB,qBAAqB,QAAuB,MAAqC;CAC/F,IAAI,KAAK,OAAO,WAAW,GAAG,OAAO,KAAA;CACrC,MAAM,QAAQ,OAAO,IAAI,iBAAiB,IAAI,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO;CACrE,IAAI,OAAO,SAAS,aAAa,CAAC,MAAM,UAAU,aAAa,OAAO,KAAA;CACtE,OAAO,kBAAkB,MAAM,SAAS,iBAAiB,cAAc,IAAI,CAAC,IAAI,MAAM,SAAS,KAAK,KAAA;AACtG"}
1
+ {"version":3,"file":"phase-automation.js","names":[],"sources":["../../src/boards/phase-automation.ts"],"sourcesContent":["import { evaluateRuleGroup } from '../rules/rule-group.js';\nimport type { FactoryCommitDecision } from '../rules/types.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport { cardRuleFacts } from './card-facts.js';\nimport { codeBoardOf } from './define-board.js';\nimport type { BoardRegistry } from './registry.js';\nimport { boardForWorkItem } from './semantics.js';\nimport { workBoard } from './work.js';\n\ntype PhaseCard = Pick<Card, 'board' | 'externalSource' | 'stages' | 'title' | 'metadata' | 'workItem'>;\n\n/**\n * Whether the decision starts the run of a phase that starts on its own for this card\n * (`autoStart`, and `autoStartWhen` when set), so it needs nobody's approval.\n */\nexport function startsInAutoPhase(boards: BoardRegistry, item: PhaseCard, decision: FactoryCommitDecision): boolean {\n if (decision.type === 'transition') {\n return boards.get(decision.board)?.startsAutomatically(decision.stage, cardRuleFacts(item)) === true;\n }\n if (decision.type !== 'invokeSkill' || item.stages.length !== 1) return false;\n const boardKey = boardForWorkItem(item);\n const board = boards.get(boardKey);\n const stage = item.stages[0]!;\n if (!board) return false;\n // Work's Review and PR review phases run the independent reviewer in its own `review` seat.\n const reviewerSeat =\n decision.role === 'review' && codeBoardOf(board) === workBoard && (stage === 'review' || stage === 'pr-review');\n const ownRun = board.roleForPhase(stage) === decision.role || reviewerSeat;\n return ownRun && board.startsAutomatically(stage, cardRuleFacts(item));\n}\n\n/** The exit tool of the card's phase when it is approved without a person for this card. */\nexport function autoApprovedExitTool(boards: BoardRegistry, item: PhaseCard): string | undefined {\n if (item.stages.length !== 1) return undefined;\n const phase = boards.get(boardForWorkItem(item))?.phases[item.stages[0]!];\n if (phase?.kind !== 'working' || !phase.exitTool?.autoApprove) return undefined;\n return evaluateRuleGroup(phase.exitTool.autoApproveWhen, cardRuleFacts(item)) ? phase.exitTool.id : undefined;\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,kBAAkB,QAAuB,MAAiB,UAA0C;CAClH,IAAI,SAAS,SAAS,cACpB,OAAO,OAAO,IAAI,SAAS,KAAK,CAAC,EAAE,oBAAoB,SAAS,OAAO,cAAc,IAAI,CAAC,MAAM;CAElG,IAAI,SAAS,SAAS,iBAAiB,KAAK,OAAO,WAAW,GAAG,OAAO;CACxE,MAAM,WAAW,iBAAiB,IAAI;CACtC,MAAM,QAAQ,OAAO,IAAI,QAAQ;CACjC,MAAM,QAAQ,KAAK,OAAO;CAC1B,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,eACJ,SAAS,SAAS,YAAY,YAAY,KAAK,MAAM,cAAc,UAAU,YAAY,UAAU;CAErG,QADe,MAAM,aAAa,KAAK,MAAM,SAAS,QAAQ,iBAC7C,MAAM,oBAAoB,OAAO,cAAc,IAAI,CAAC;AACvE;;AAGA,SAAgB,qBAAqB,QAAuB,MAAqC;CAC/F,IAAI,KAAK,OAAO,WAAW,GAAG,OAAO,KAAA;CACrC,MAAM,QAAQ,OAAO,IAAI,iBAAiB,IAAI,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO;CACrE,IAAI,OAAO,SAAS,aAAa,CAAC,MAAM,UAAU,aAAa,OAAO,KAAA;CACtE,OAAO,kBAAkB,MAAM,SAAS,iBAAiB,cAAc,IAAI,CAAC,IAAI,MAAM,SAAS,KAAK,KAAA;AACtG"}
@@ -1,11 +1,14 @@
1
1
  import type { InlineSkill } from '@mastra/core/skills';
2
- import type { StoredBoardScope, StoredBoardsStorage } from '../storage/domains/boards/base.js';
2
+ import type { StoredBoardInput, StoredBoardScope, StoredBoardsStorage } from '../storage/domains/boards/base.js';
3
3
  import type { BoardRegistry } from './registry.js';
4
4
  /** Where a board in a project's catalog came from. */
5
5
  export type BoardSourceKind = 'builtin' | 'app' | 'stored';
6
6
  export interface StoredBoardDetails {
7
7
  source: BoardSourceKind;
8
- /** Only boards the project stored can be edited; code boards are read-only. */
8
+ /**
9
+ * Stored boards, the built-in Work board and app boards can be edited; the legacy Review board,
10
+ * which is being retired, stays read-only.
11
+ */
9
12
  editable: boolean;
10
13
  problems: string[];
11
14
  }
@@ -48,16 +51,24 @@ export interface ProjectBoardCacheOptions {
48
51
  warn?: (message: string) => void;
49
52
  }
50
53
  /**
51
- * The per-project board cache. A project's boards are the code boards, served as code built them
52
- * and winning on their key, followed by the boards the project stored. Loads recheck the
53
- * project's board version at most every `recheckMs` and recompile when it changed, so stored
54
- * edits on other replicas arrive within that delay. The cache never writes.
54
+ * The per-project board cache. A project's boards are its rows: the Work and app boards Factory
55
+ * stored in it, in code order, then the others. A Work or app board's row runs with the code
56
+ * behaviour of its board and phase keys that still fits it ({@link mergeCodeBehaviour}); only the
57
+ * legacy Review board is served from code. The first load of each project in a process stores the
58
+ * boards Factory hasn't stored in it yet, each once ({@link StoredBoardsStorage.seedBoards}); a
59
+ * release never rewrites them. Loads recheck the project's board version at most every
60
+ * `recheckMs` and recompile when it changed, so stored edits on other replicas arrive within that
61
+ * delay.
55
62
  */
56
63
  export declare class ProjectBoardCache implements ProjectBoardSource {
57
64
  #private;
58
65
  readonly [PROJECT_BOARD_SOURCE] = true;
59
66
  readonly codeRegistry: BoardRegistry;
60
67
  constructor(options: ProjectBoardCacheOptions);
68
+ /** The boards Factory stores in each project once, in order. */
69
+ seeds(): StoredBoardInput[];
70
+ /** Factory's current definition for `key`, which reset restores; undefined when Factory has none. */
71
+ seedFor(key: string): StoredBoardInput | undefined;
61
72
  load(scope: StoredBoardScope): Promise<BoardRegistry>;
62
73
  /** The project's boards with their source, whether they can be edited, and problems, brought up to date. */
63
74
  describe(scope: StoredBoardScope): Promise<ProjectBoards>;
@@ -71,7 +82,7 @@ export declare class ProjectBoardCache implements ProjectBoardSource {
71
82
  get codeSkills(): readonly InlineSkill[];
72
83
  /** Makes the next load reread the project. The loaded boards keep serving sync reads until then. */
73
84
  invalidate(scope: StoredBoardScope): void;
74
- /** Loads every project, a few at a time, so sync reads find them warm. */
85
+ /** Loads every project, a few at a time, so sync reads find them warm and each has its boards stored. */
75
86
  preload(): Promise<void>;
76
87
  }
77
88
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"project-boards.d.ts","sourceRoot":"","sources":["../../src/boards/project-boards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,KAAK,EAAqB,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAElH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAOnE,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,eAAe,CAAC;IACxB,+EAA+E;IAC/E,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,uGAAuG;AACvG,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC1D,qEAAqE;IACrE,QAAQ,CA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