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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +110 -56
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +7 -1
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/board-events.d.ts +1 -1
  6. package/dist/boards/board-events.d.ts.map +1 -1
  7. package/dist/boards/card-facts.d.ts +3 -1
  8. package/dist/boards/card-facts.d.ts.map +1 -1
  9. package/dist/boards/card-facts.js +26 -4
  10. package/dist/boards/card-facts.js.map +1 -1
  11. package/dist/boards/default-board.d.ts +2 -2
  12. package/dist/boards/default-board.js +2 -2
  13. package/dist/boards/default-board.js.map +1 -1
  14. package/dist/boards/define-board.d.ts +1 -1
  15. package/dist/boards/define-board.d.ts.map +1 -1
  16. package/dist/boards/define-board.js.map +1 -1
  17. package/dist/boards/intake-routing.d.ts +3 -5
  18. package/dist/boards/intake-routing.d.ts.map +1 -1
  19. package/dist/boards/intake-routing.js +3 -4
  20. package/dist/boards/intake-routing.js.map +1 -1
  21. package/dist/boards/project-boards.d.ts +18 -1
  22. package/dist/boards/project-boards.d.ts.map +1 -1
  23. package/dist/boards/project-boards.js +40 -3
  24. package/dist/boards/project-boards.js.map +1 -1
  25. package/dist/boards/semantics.d.ts +4 -4
  26. package/dist/boards/semantics.d.ts.map +1 -1
  27. package/dist/boards/semantics.js +8 -10
  28. package/dist/boards/semantics.js.map +1 -1
  29. package/dist/boards/work-migrations.d.ts +24 -1
  30. package/dist/boards/work-migrations.d.ts.map +1 -1
  31. package/dist/boards/work-migrations.js +97 -2
  32. package/dist/boards/work-migrations.js.map +1 -1
  33. package/dist/boards/work-routes.d.ts +6 -1
  34. package/dist/boards/work-routes.d.ts.map +1 -1
  35. package/dist/boards/work-routes.js +20 -6
  36. package/dist/boards/work-routes.js.map +1 -1
  37. package/dist/factory.d.ts +23 -0
  38. package/dist/factory.d.ts.map +1 -1
  39. package/dist/factory.js +62 -59
  40. package/dist/factory.js.map +1 -1
  41. package/dist/feed-events.d.ts +3 -2
  42. package/dist/feed-events.d.ts.map +1 -1
  43. package/dist/feed-events.js +3 -2
  44. package/dist/feed-events.js.map +1 -1
  45. package/dist/index.d.ts +3 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +2 -1
  48. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  49. package/dist/integrations/github/default-rules.js +3 -5
  50. package/dist/integrations/github/default-rules.js.map +1 -1
  51. package/dist/integrations/github/rules.d.ts +0 -6
  52. package/dist/integrations/github/rules.d.ts.map +1 -1
  53. package/dist/integrations/github/rules.js +23 -70
  54. package/dist/integrations/github/rules.js.map +1 -1
  55. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  56. package/dist/integrations/gitlab/routes.js +1 -3
  57. package/dist/integrations/gitlab/routes.js.map +1 -1
  58. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  59. package/dist/integrations/gitlab/rules.js +4 -9
  60. package/dist/integrations/gitlab/rules.js.map +1 -1
  61. package/dist/integrations/incidentio/agent-tools.js +5 -5
  62. package/dist/integrations/incidentio/agent-tools.js.map +1 -1
  63. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
  64. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  65. package/dist/integrations/incidentio/routes.d.ts +2 -2
  66. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  67. package/dist/integrations/incidentio/routes.js +10 -13
  68. package/dist/integrations/incidentio/routes.js.map +1 -1
  69. package/dist/integrations/incidentio/rules.d.ts +1 -3
  70. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  71. package/dist/integrations/incidentio/rules.js +1 -3
  72. package/dist/integrations/incidentio/rules.js.map +1 -1
  73. package/dist/integrations/jira/binding-scope.d.ts +5 -6
  74. package/dist/integrations/jira/binding-scope.d.ts.map +1 -1
  75. package/dist/integrations/jira/binding-scope.js +9 -11
  76. package/dist/integrations/jira/binding-scope.js.map +1 -1
  77. package/dist/integrations/jira/default-rules.d.ts.map +1 -1
  78. package/dist/integrations/jira/default-rules.js.map +1 -1
  79. package/dist/integrations/jira/routes.d.ts.map +1 -1
  80. package/dist/integrations/jira/routes.js +3 -5
  81. package/dist/integrations/jira/routes.js.map +1 -1
  82. package/dist/integrations/jira/rules.d.ts +1 -3
  83. package/dist/integrations/jira/rules.d.ts.map +1 -1
  84. package/dist/integrations/jira/rules.js +1 -3
  85. package/dist/integrations/jira/rules.js.map +1 -1
  86. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  87. package/dist/integrations/linear/default-rules.js.map +1 -1
  88. package/dist/integrations/linear/routes.d.ts.map +1 -1
  89. package/dist/integrations/linear/routes.js +11 -14
  90. package/dist/integrations/linear/routes.js.map +1 -1
  91. package/dist/integrations/linear/rules.d.ts +1 -3
  92. package/dist/integrations/linear/rules.d.ts.map +1 -1
  93. package/dist/integrations/linear/rules.js +1 -3
  94. package/dist/integrations/linear/rules.js.map +1 -1
  95. package/dist/integrations/platform/connect/session-tools.d.ts +5 -0
  96. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
  97. package/dist/integrations/platform/connect/session-tools.js +5 -0
  98. package/dist/integrations/platform/connect/session-tools.js.map +1 -1
  99. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  100. package/dist/integrations/platform/jira/routes.js +3 -5
  101. package/dist/integrations/platform/jira/routes.js.map +1 -1
  102. package/dist/integrations/slack/run-error-card.js +1 -0
  103. package/dist/integrations/slack/run-error-card.js.map +1 -1
  104. package/dist/provider-display-name.d.ts.map +1 -1
  105. package/dist/provider-display-name.js +1 -0
  106. package/dist/provider-display-name.js.map +1 -1
  107. package/dist/routes/automation-runs.d.ts +1 -1
  108. package/dist/routes/automation-runs.js.map +1 -1
  109. package/dist/routes/config.d.ts +7 -1
  110. package/dist/routes/config.d.ts.map +1 -1
  111. package/dist/routes/config.js +105 -22
  112. package/dist/routes/config.js.map +1 -1
  113. package/dist/routes/contracts.d.ts +3 -10
  114. package/dist/routes/contracts.d.ts.map +1 -1
  115. package/dist/routes/contracts.js +11 -9
  116. package/dist/routes/contracts.js.map +1 -1
  117. package/dist/routes/intake-routes.d.ts.map +1 -1
  118. package/dist/routes/intake-routes.js +6 -1
  119. package/dist/routes/intake-routes.js.map +1 -1
  120. package/dist/routes/intake.d.ts +0 -23
  121. package/dist/routes/intake.d.ts.map +1 -1
  122. package/dist/routes/intake.js +13 -310
  123. package/dist/routes/intake.js.map +1 -1
  124. package/dist/routes/mastra-gateway.d.ts +19 -0
  125. package/dist/routes/mastra-gateway.d.ts.map +1 -0
  126. package/dist/routes/mastra-gateway.js +120 -0
  127. package/dist/routes/mastra-gateway.js.map +1 -0
  128. package/dist/routes/projects.d.ts.map +1 -1
  129. package/dist/routes/projects.js +1 -1
  130. package/dist/routes/projects.js.map +1 -1
  131. package/dist/routes/provider-credentials.d.ts +6 -1
  132. package/dist/routes/provider-credentials.d.ts.map +1 -1
  133. package/dist/routes/provider-credentials.js +32 -2
  134. package/dist/routes/provider-credentials.js.map +1 -1
  135. package/dist/routes/route.d.ts +6 -0
  136. package/dist/routes/route.d.ts.map +1 -1
  137. package/dist/routes/route.js.map +1 -1
  138. package/dist/routes/surface.d.ts.map +1 -1
  139. package/dist/routes/surface.js +0 -2
  140. package/dist/routes/surface.js.map +1 -1
  141. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  142. package/dist/routes/tenant-credentials.js +5 -1
  143. package/dist/routes/tenant-credentials.js.map +1 -1
  144. package/dist/rules/dispatcher.d.ts +0 -5
  145. package/dist/rules/dispatcher.d.ts.map +1 -1
  146. package/dist/rules/dispatcher.js +18 -22
  147. package/dist/rules/dispatcher.js.map +1 -1
  148. package/dist/rules/rule-group.d.ts +1 -1
  149. package/dist/rules/rule-group.d.ts.map +1 -1
  150. package/dist/rules/rule-group.js +13 -5
  151. package/dist/rules/rule-group.js.map +1 -1
  152. package/dist/rules/transition-service.d.ts +2 -3
  153. package/dist/rules/transition-service.d.ts.map +1 -1
  154. package/dist/rules/transition-service.js +0 -1
  155. package/dist/rules/transition-service.js.map +1 -1
  156. package/dist/rules/types.d.ts +7 -11
  157. package/dist/rules/types.d.ts.map +1 -1
  158. package/dist/rules/types.js.map +1 -1
  159. package/dist/run-error.d.ts +1 -1
  160. package/dist/run-error.d.ts.map +1 -1
  161. package/dist/run-error.js +38 -5
  162. package/dist/run-error.js.map +1 -1
  163. package/dist/session/live-sessions.d.ts +11 -4
  164. package/dist/session/live-sessions.d.ts.map +1 -1
  165. package/dist/session/live-sessions.js +31 -10
  166. package/dist/session/live-sessions.js.map +1 -1
  167. package/dist/session/self-review-gate.d.ts +0 -2
  168. package/dist/session/self-review-gate.d.ts.map +1 -1
  169. package/dist/session/self-review-gate.js +1 -8
  170. package/dist/session/self-review-gate.js.map +1 -1
  171. package/dist/session/source-control-tools.d.ts +39 -13
  172. package/dist/session/source-control-tools.d.ts.map +1 -1
  173. package/dist/session/source-control-tools.js +54 -60
  174. package/dist/session/source-control-tools.js.map +1 -1
  175. package/dist/session/work-item-state-processor.d.ts +1 -4
  176. package/dist/session/work-item-state-processor.d.ts.map +1 -1
  177. package/dist/session/work-item-state-processor.js +5 -18
  178. package/dist/session/work-item-state-processor.js.map +1 -1
  179. package/dist/storage/domains/boards/base.d.ts +30 -8
  180. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  181. package/dist/storage/domains/boards/base.js +43 -25
  182. package/dist/storage/domains/boards/base.js.map +1 -1
  183. package/dist/storage/domains/boards/schemas.js.map +1 -1
  184. package/dist/storage/domains/comments/base.d.ts.map +1 -1
  185. package/dist/storage/domains/comments/base.js +2 -2
  186. package/dist/storage/domains/comments/base.js.map +1 -1
  187. package/dist/storage/domains/comments/routes.d.ts.map +1 -1
  188. package/dist/storage/domains/comments/routes.js +4 -2
  189. package/dist/storage/domains/comments/routes.js.map +1 -1
  190. package/dist/storage/domains/intake/base.d.ts +5 -45
  191. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  192. package/dist/storage/domains/intake/base.js +11 -89
  193. package/dist/storage/domains/intake/base.js.map +1 -1
  194. package/dist/storage/domains/projects/base.d.ts +17 -9
  195. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  196. package/dist/storage/domains/projects/base.js +15 -7
  197. package/dist/storage/domains/projects/base.js.map +1 -1
  198. package/dist/storage/domains/work-items/base.d.ts +13 -11
  199. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  200. package/dist/storage/domains/work-items/base.js +37 -33
  201. package/dist/storage/domains/work-items/base.js.map +1 -1
  202. package/dist/storage/domains/work-items/board-version.d.ts +6 -2
  203. package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
  204. package/dist/storage/domains/work-items/board-version.js +20 -9
  205. package/dist/storage/domains/work-items/board-version.js.map +1 -1
  206. package/dist/work-items/providers/base.d.ts +4 -1
  207. package/dist/work-items/providers/base.d.ts.map +1 -1
  208. package/dist/work-items/providers/base.js +6 -1
  209. package/dist/work-items/providers/base.js.map +1 -1
  210. package/dist/work-items/providers/github.d.ts.map +1 -1
  211. package/dist/work-items/providers/github.js +2 -1
  212. package/dist/work-items/providers/github.js.map +1 -1
  213. package/dist/work-items/providers/gitlab.d.ts.map +1 -1
  214. package/dist/work-items/providers/gitlab.js +2 -1
  215. package/dist/work-items/providers/gitlab.js.map +1 -1
  216. package/dist/work-items/providers/jira.d.ts.map +1 -1
  217. package/dist/work-items/providers/jira.js +3 -2
  218. package/dist/work-items/providers/jira.js.map +1 -1
  219. package/dist/work-items/providers/linear.d.ts.map +1 -1
  220. package/dist/work-items/providers/linear.js +3 -2
  221. package/dist/work-items/providers/linear.js.map +1 -1
  222. package/dist/work-items/providers/types.d.ts +6 -0
  223. package/dist/work-items/providers/types.d.ts.map +1 -1
  224. package/factory-skills/configure-factory-rules/SKILL.md +2 -2
  225. package/factory-skills/factory-build/SKILL.md +5 -5
  226. package/factory-skills/factory-gitlab-rereview/SKILL.md +4 -4
  227. package/factory-skills/factory-gitlab-review/SKILL.md +5 -5
  228. package/factory-skills/factory-rereview/SKILL.md +69 -23
  229. package/factory-skills/factory-review/SKILL.md +69 -23
  230. package/factory-skills/factory-self-review/SKILL.md +5 -6
  231. package/factory-skills/factory-triage/SKILL.md +8 -20
  232. package/package.json +8 -8
@@ -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_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 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 type { BoardTransitionPolicy } from './transition-policy.js';\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\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 * Seat review runs sit in. Review skills load only in it, it is the only seat granted the verdict\n * tool, and its sessions check out code the author wrote, so they never trust that checkout's\n * instruction files. A runner context, not a phase key: any board's phases may run in it.\n */\nexport const REVIEW_CONTEXT = 'review';\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. Without one, entering the phase starts no run. */\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 * Pursue the phase's work as a goal: the run's thread holds `objective` and the agent's goal\n * judge keeps it working until the objective is met. The judge sees only this text and the\n * latest messages, so it must say when the work is done.\n */\n readonly goal?: BoardPhaseGoal;\n}\n\n/** The objective a phase's runs pursue, judged in-loop until met. */\nexport interface BoardPhaseGoal {\n readonly objective: string;\n /** Judged turns before the goal pauses for a person; defaults to the agent's setting. */\n readonly maxRuns?: number;\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\n/** Factory tools a working phase grants the session that works the card there. */\nexport const FACTORY_PHASE_TOOLS = ['factory_record_review_verdict', 'factory_review_source'] as const;\nexport type FactoryPhaseTool = (typeof FACTORY_PHASE_TOOLS)[number];\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 /** @deprecated Ignored apart from its targets, which are allowed next phases; list them in `nextPhases`. */\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n /** @deprecated Ignored; a phase starts its run from `runner.skill`. */\n readonly onEnter?: Readonly<Record<string, unknown>>;\n /** @deprecated Ignored; a phase starts its run from `runner.skill`. */\n readonly onExit?: Readonly<Record<string, unknown>>;\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 * Factory tools the session working the card here gets, on top of the move tool. Only the\n * session whose context is the phase's `runner.context` gets them, and only while the card\n * is in this phase.\n */\n readonly tools?: readonly FactoryPhaseTool[];\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 readonly tools?: 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. */\n readonly nextPhases: readonly PhaseId[];\n /** @deprecated Use `nextPhases`; set when the phase declared `next`. */\n readonly next?: PhaseId;\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 readonly tools?: readonly FactoryPhaseTool[];\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 /** Always null: boards no longer name their moves. */\n readonly outcome: 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 /** 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 MAX_GOAL_OBJECTIVE_LENGTH = 2_000;\nconst MAX_GOAL_RUNS = 50;\nconst RUNNER_KEYS: ReadonlySet<string> = new Set(['agentId', 'skill', 'context', 'instructions', 'goal']);\nconst GOAL_KEYS: ReadonlySet<string> = new Set(['objective', 'maxRuns']);\nconst EXIT_TOOL_KEYS: ReadonlySet<string> = new Set(['id', 'autoApprove', 'autoApproveWhen']);\nconst WORKING_ONLY_FIELDS = ['runner', 'autoStart', 'autoStartWhen', 'exitTool', 'tools'] as const;\nconst MOVE_TOOL = 'factory_transition_work_item';\n\nfunction resolvePhaseTools(label: string, value: unknown): readonly FactoryPhaseTool[] | undefined {\n if (value === undefined) return undefined;\n if (!Array.isArray(value)) throw new BoardDefinitionError(`${label} tools must be a list of Factory tool names.`);\n for (const tool of value) {\n if (!(FACTORY_PHASE_TOOLS as readonly unknown[]).includes(tool)) {\n throw new BoardDefinitionError(`${label} tools: ${String(tool)} is not a Factory phase tool.`);\n }\n }\n const tools = [...new Set(value as FactoryPhaseTool[])];\n return tools.length ? Object.freeze(tools) : undefined;\n}\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(\n `Phase \"${phaseId}\" runner may only set agentId, skill, context, instructions and goal.`,\n );\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 const goal = resolveGoal(phaseId, runner.goal);\n if (goal !== undefined && skill === undefined) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" runner.goal needs runner.skill: the skill's run pursues the goal.`,\n );\n }\n return Object.freeze({\n agentId,\n context,\n ...(skill !== undefined ? { skill } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n ...(goal !== undefined ? { goal } : {}),\n });\n}\n\nfunction resolveGoal(phaseId: string, value: unknown): BoardPhaseGoal | undefined {\n if (value === undefined) return undefined;\n if (!isPlainObject(value) || Object.keys(value).some(key => !GOAL_KEYS.has(key))) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.goal may only set objective and maxRuns.`);\n }\n const objective = optionalText(\n value.objective,\n `Phase \"${phaseId}\" runner.goal.objective`,\n MAX_GOAL_OBJECTIVE_LENGTH,\n );\n if (objective === undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.goal must state an objective.`);\n }\n const maxRuns = value.maxRuns;\n if (\n maxRuns !== undefined &&\n (typeof maxRuns !== 'number' || !Number.isInteger(maxRuns) || maxRuns < 1 || maxRuns > MAX_GOAL_RUNS)\n ) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" runner.goal.maxRuns must be a whole number from 1 to ${MAX_GOAL_RUNS}.`,\n );\n }\n return Object.freeze({ objective, ...(maxRuns !== undefined ? { maxRuns } : {}) });\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\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 if (phase.outcomes !== undefined) found.push(`phases.${phaseId}.outcomes → nextPhases`);\n }\n return found;\n}\n\n/** Fields a board declaration still passes that Factory no longer reads. */\nfunction ignoredFields(config: DeclaredBoard): string[] {\n const found: string[] = [];\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n for (const field of ['onEnter', 'onExit'] as const) {\n if (phase[field] !== undefined) found.push(`phases.${phaseId}.${field}`);\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 const ignored = ignoredFields(config);\n if (found.length === 0 && ignored.length === 0) return;\n warnedBoards.add(config.id);\n const warnings: string[] = [];\n if (found.length > 0) {\n warnings.push(\n `uses deprecated fields: ${found.join(', ')}. They still work but will be removed in a future release.`,\n );\n }\n if (ignored.length > 0) {\n warnings.push(`declares ${ignored.join(', ')}, which are ignored; use runner.skill to start a phase's run.`);\n }\n console.warn(`[Mastra Factory] Board \"${config.id}\" ${warnings.join(' It also ')}`);\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/** The declaration a board was built from, so a stored definition can reuse its code behaviour. */\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.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 // A deprecated `outcomes` map still names moves the board allows.\n for (const to of [\n ...(phase.next !== undefined ? [phase.next] : []),\n ...Object.values(phase.outcomes ?? {}),\n ...(phase.nextPhases ?? []),\n ]) {\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 const tools = resolvePhaseTools(label, working?.tools);\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 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 ...(runner ? { runner, role: runner.context } : {}),\n ...(working?.autoStart ? { autoStart: true } : {}),\n ...(autoStartWhen ? { autoStartWhen } : {}),\n ...(exitTool ? { exitTool } : {}),\n ...(tools ? { tools } : {}),\n }),\n ];\n }),\n ),\n ) as Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\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 tools,\n events,\n ...(config.transitionPolicy ? { transitionPolicy: config.transitionPolicy } : {}),\n ...(sourceClosed ? { sourceClosed } : {}),\n allowsTransition(from: PhaseId, to: PhaseId) {\n if (!kinds.has(from) || !kinds.has(to)) return false;\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":";;;;;AA6DA,MAAM,oBAAgF;CACpF,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,YAAY;AACd;;AAWA,MAAa,mBAAmB;;AAGhC,MAAa,wBAAwB;;;;;;AAMrC,MAAa,iBAAiB;;AA8C9B,MAAa,sBAAsB,CAAC,iCAAiC,uBAAuB;AAiJ5F,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,4BAA4B;AAClC,MAAM,gBAAgB;AACtB,MAAM,8BAAmC,IAAI,IAAI;CAAC;CAAW;CAAS;CAAW;CA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{ 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_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 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 type { BoardTransitionPolicy } from './transition-policy.js';\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\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 * Seat review runs sit in. Review skills load only in it, it is the only seat granted the verdict\n * tool, and its sessions check out code the author wrote, so they never trust that checkout's\n * instruction files. A runner context, not a phase key: any board's phases may run in it.\n */\nexport const REVIEW_CONTEXT = 'review';\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. Without one, entering the phase starts no run. */\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 * Pursue the phase's work as a goal: the run's thread holds `objective` and the agent's goal\n * judge keeps it working until the objective is met. The judge sees only this text and the\n * latest messages, so it must say when the work is done.\n */\n readonly goal?: BoardPhaseGoal;\n}\n\n/** The objective a phase's runs pursue, judged in-loop until met. */\nexport interface BoardPhaseGoal {\n readonly objective: string;\n /** Judged turns before the goal pauses for a person; defaults to the agent's setting. */\n readonly maxRuns?: number;\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\n/** Factory tools a working phase grants the session that works the card there. */\nexport const FACTORY_PHASE_TOOLS = ['factory_record_review_verdict', 'factory_review_source'] as const;\nexport type FactoryPhaseTool = (typeof FACTORY_PHASE_TOOLS)[number];\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 /** @deprecated Ignored apart from its targets, which are allowed next phases; list them in `nextPhases`. */\n readonly outcomes?: Readonly<Record<string, PhaseId>>;\n /** @deprecated Ignored; a phase starts its run from `runner.skill`. */\n readonly onEnter?: Readonly<Record<string, unknown>>;\n /** @deprecated Ignored; a phase starts its run from `runner.skill`. */\n readonly onExit?: Readonly<Record<string, unknown>>;\n};\n\ntype WorkingPhaseFields = {\n readonly runner?: BoardPhaseRunner;\n /** @deprecated Use `runner.context`. */\n readonly role?: string;\n /** Runs start without anyone approving them. The board, not a project setting, decides this. */\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 * Factory tools the session working the card here gets, on top of the move tool. Only the\n * session whose context is the phase's `runner.context` gets them, and only while the card\n * is in this phase.\n */\n readonly tools?: readonly FactoryPhaseTool[];\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 readonly tools?: 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. */\n readonly nextPhases: readonly PhaseId[];\n /** @deprecated Use `nextPhases`; set when the phase declared `next`. */\n readonly next?: PhaseId;\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 readonly tools?: readonly FactoryPhaseTool[];\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 /** Always null: boards no longer name their moves. */\n readonly outcome: 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 /** 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 MAX_GOAL_OBJECTIVE_LENGTH = 2_000;\nconst MAX_GOAL_RUNS = 50;\nconst RUNNER_KEYS: ReadonlySet<string> = new Set(['agentId', 'skill', 'context', 'instructions', 'goal']);\nconst GOAL_KEYS: ReadonlySet<string> = new Set(['objective', 'maxRuns']);\nconst EXIT_TOOL_KEYS: ReadonlySet<string> = new Set(['id', 'autoApprove', 'autoApproveWhen']);\nconst WORKING_ONLY_FIELDS = ['runner', 'autoStart', 'autoStartWhen', 'exitTool', 'tools'] as const;\nconst MOVE_TOOL = 'factory_transition_work_item';\n\nfunction resolvePhaseTools(label: string, value: unknown): readonly FactoryPhaseTool[] | undefined {\n if (value === undefined) return undefined;\n if (!Array.isArray(value)) throw new BoardDefinitionError(`${label} tools must be a list of Factory tool names.`);\n for (const tool of value) {\n if (!(FACTORY_PHASE_TOOLS as readonly unknown[]).includes(tool)) {\n throw new BoardDefinitionError(`${label} tools: ${String(tool)} is not a Factory phase tool.`);\n }\n }\n const tools = [...new Set(value as FactoryPhaseTool[])];\n return tools.length ? Object.freeze(tools) : undefined;\n}\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(\n `Phase \"${phaseId}\" runner may only set agentId, skill, context, instructions and goal.`,\n );\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 const goal = resolveGoal(phaseId, runner.goal);\n if (goal !== undefined && skill === undefined) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" runner.goal needs runner.skill: the skill's run pursues the goal.`,\n );\n }\n return Object.freeze({\n agentId,\n context,\n ...(skill !== undefined ? { skill } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n ...(goal !== undefined ? { goal } : {}),\n });\n}\n\nfunction resolveGoal(phaseId: string, value: unknown): BoardPhaseGoal | undefined {\n if (value === undefined) return undefined;\n if (!isPlainObject(value) || Object.keys(value).some(key => !GOAL_KEYS.has(key))) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.goal may only set objective and maxRuns.`);\n }\n const objective = optionalText(\n value.objective,\n `Phase \"${phaseId}\" runner.goal.objective`,\n MAX_GOAL_OBJECTIVE_LENGTH,\n );\n if (objective === undefined) {\n throw new BoardDefinitionError(`Phase \"${phaseId}\" runner.goal must state an objective.`);\n }\n const maxRuns = value.maxRuns;\n if (\n maxRuns !== undefined &&\n (typeof maxRuns !== 'number' || !Number.isInteger(maxRuns) || maxRuns < 1 || maxRuns > MAX_GOAL_RUNS)\n ) {\n throw new BoardDefinitionError(\n `Phase \"${phaseId}\" runner.goal.maxRuns must be a whole number from 1 to ${MAX_GOAL_RUNS}.`,\n );\n }\n return Object.freeze({ objective, ...(maxRuns !== undefined ? { maxRuns } : {}) });\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\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 if (phase.outcomes !== undefined) found.push(`phases.${phaseId}.outcomes → nextPhases`);\n }\n return found;\n}\n\n/** Fields a board declaration still passes that Factory no longer reads. */\nfunction ignoredFields(config: DeclaredBoard): string[] {\n const found: string[] = [];\n for (const [phaseId, phase] of Object.entries(config.phases)) {\n for (const field of ['onEnter', 'onExit'] as const) {\n if (phase[field] !== undefined) found.push(`phases.${phaseId}.${field}`);\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 const ignored = ignoredFields(config);\n if (found.length === 0 && ignored.length === 0) return;\n warnedBoards.add(config.id);\n const warnings: string[] = [];\n if (found.length > 0) {\n warnings.push(\n `uses deprecated fields: ${found.join(', ')}. They still work but will be removed in a future release.`,\n );\n }\n if (ignored.length > 0) {\n warnings.push(`declares ${ignored.join(', ')}, which are ignored; use runner.skill to start a phase's run.`);\n }\n console.warn(`[Mastra Factory] Board \"${config.id}\" ${warnings.join(' It also ')}`);\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/** The declaration a board was built from, so a stored definition can reuse its code behaviour. */\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.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 // A deprecated `outcomes` map still names moves the board allows.\n for (const to of [\n ...(phase.next !== undefined ? [phase.next] : []),\n ...Object.values(phase.outcomes ?? {}),\n ...(phase.nextPhases ?? []),\n ]) {\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 const tools = resolvePhaseTools(label, working?.tools);\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 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 ...(runner ? { runner, role: runner.context } : {}),\n ...(working?.autoStart ? { autoStart: true } : {}),\n ...(autoStartWhen ? { autoStartWhen } : {}),\n ...(exitTool ? { exitTool } : {}),\n ...(tools ? { tools } : {}),\n }),\n ];\n }),\n ),\n ) as Readonly<Record<PhaseId, BoardPhase<PhaseId>>>;\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 tools,\n events,\n ...(config.transitionPolicy ? { transitionPolicy: config.transitionPolicy } : {}),\n ...(sourceClosed ? { sourceClosed } : {}),\n allowsTransition(from: PhaseId, to: PhaseId) {\n if (!kinds.has(from) || !kinds.has(to)) return false;\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":";;;;;AA6DA,MAAM,oBAAgF;CACpF,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,YAAY;AACd;;AAWA,MAAa,mBAAmB;;AAGhC,MAAa,wBAAwB;;;;;;AAMrC,MAAa,iBAAiB;;AA8C9B,MAAa,sBAAsB,CAAC,iCAAiC,uBAAuB;AAiJ5F,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,4BAA4B;AAClC,MAAM,gBAAgB;AACtB,MAAM,8BAAmC,IAAI,IAAI;CAAC;CAAW;CAAS;CAAW;CAAgB;AAAM,CAAC;AACxG,MAAM,4BAAiC,IAAI,IAAI,CAAC,aAAa,SAAS,CAAC;AACvE,MAAM,iCAAsC,IAAI,IAAI;CAAC;CAAM;CAAe;AAAiB,CAAC;AAC5F,MAAM,sBAAsB;CAAC;CAAU;CAAa;CAAiB;CAAY;AAAO;AACxF,MAAM,YAAY;AAElB,SAAS,kBAAkB,OAAe,OAAyD;CACjG,IAAI,UAAU,KAAA,GAAW,O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AC;EAC/E,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;EACvC,iBAAiB,MAAe,IAAa;GAC3C,IAAI,CAAC,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,GAAG,OAAO;GAC/C,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,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"}
@@ -6,12 +6,11 @@ import type { BoardRegistry, InstalledBoard } from './registry.js';
6
6
  /** Reads a project's intake routes, in order. */
7
7
  export type IntakeRoutesReader = Pick<StoredBoardsStorage, 'listIntakeRoutes'>;
8
8
  type IntakeRoute = Pick<StoredIntakeRouteRecord, 'id' | 'enabled' | 'when' | 'target' | 'on'>;
9
- type EventRoute = IntakeRoute & Pick<StoredIntakeRouteRecord, 'allowWorkingPhase'>;
10
9
  /** Whether the route places new cards, rather than only moving existing ones on later events. */
11
10
  export declare function placesNewCards(route: Pick<StoredIntakeRouteRecord, 'on'>): boolean;
12
11
  /**
13
- * Card metadata naming the intake route that placed the card. Label routes, repository
14
- * bindings and replayed arrivals leave such a card where the route put it.
12
+ * Card metadata naming the intake route that placed the card. Label changes, rebinding its
13
+ * source and replayed arrivals leave such a card where the route put it.
15
14
  */
16
15
  export declare const INTAKE_ROUTE_METADATA_KEY = "intakeRouteId";
17
16
  /** Whether an intake route chose this card's board when it arrived. */
@@ -74,10 +73,9 @@ export declare function routesHandleEvent(routes: readonly Pick<IntakeRoute, 'on
74
73
  * hold it there. A route without a phase moves the card to its board's first phase. Undefined
75
74
  * leaves the card where it is.
76
75
  */
77
- export declare function resolveEventRoute(routes: readonly EventRoute[], event: BoardEventFacts, cardFacts: RuleFacts, board: InstalledBoard, carriesPullRequest?: boolean): {
76
+ export declare function resolveEventRoute(routes: readonly IntakeRoute[], event: BoardEventFacts, cardFacts: RuleFacts, board: InstalledBoard, carriesPullRequest?: boolean): {
78
77
  phase: string;
79
78
  routeId: string;
80
- allowWorkingPhase: boolean;
81
79
  } | undefined;
82
80
  export {};
83
81
  //# 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,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGnE,iDAAiD;AACjD,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;AAE/E,KAAK,WAAW,GAAG,IAAI,CAAC,uBA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K,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,GAChC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,cAAc,EACrB,kBAAkB,UAAQ,GACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAchD"}
@@ -6,8 +6,8 @@ function placesNewCards(route) {
6
6
  return route.on.includes("work_item.created");
7
7
  }
8
8
  /**
9
- * Card metadata naming the intake route that placed the card. Label routes, repository
10
- * bindings and replayed arrivals leave such a card where the route put it.
9
+ * Card metadata naming the intake route that placed the card. Label changes, rebinding its
10
+ * source and replayed arrivals leave such a card where the route put it.
11
11
  */
12
12
  const INTAKE_ROUTE_METADATA_KEY = "intakeRouteId";
13
13
  /** Whether an intake route chose this card's board when it arrived. */
@@ -151,8 +151,7 @@ function resolveEventRoute(routes, event, cardFacts, board, carriesPullRequest =
151
151
  if (board.phaseKind(phase) === void 0 || !placementTakesCard(board, phase, facts, carriesPullRequest)) continue;
152
152
  return {
153
153
  phase,
154
- routeId: route.id,
155
- allowWorkingPhase: route.allowWorkingPhase
154
+ routeId: route.id
156
155
  };
157
156
  }
158
157
  }
@@ -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 { BoardEventFacts } from './board-events.js';\nimport type { BoardRegistry, InstalledBoard } from './registry.js';\nimport { boardFlow, boardForWorkItem, hasPullRequest } from './semantics.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' | 'join_on_event';\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; joinClosedIssue?: boolean }; 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.joinClosedIssue && route.on.some(event => event !== 'work_item.created')) {\n return {\n code: 'join_on_event',\n message:\n 'A route that joins a pull request to the card of the issue it closes handles only arrivals: its `on` must be `work_item.created` alone.',\n };\n }\n if (!target.phaseKey) return undefined;\n if (target.joinClosedIssue && board.phaseKind(target.phaseKey) === 'terminal') {\n return {\n code: 'terminal_phase',\n message: `Phase \"${target.phaseKey}\" on board \"${target.boardKey}\" is terminal; a card a pull request joins can't move there.`,\n };\n }\n if (target.joinClosedIssue) {\n return board.phaseKind(target.phaseKey)\n ? undefined\n : { code: 'unknown_phase', message: `Board \"${target.boardKey}\" has no phase \"${target.phaseKey}\".` };\n }\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 * On a board that reviews pull requests a pull request card works only in the pull request review\n * phase (it may also rest or finish), and nothing else lands in that review: a card arriving here\n * carries no attached pull request yet, and an existing issue card enters it only with one on it.\n * `FactoryTransitionService` refuses any move that breaks this, so a route can't either.\n */\nfunction placementTakesCard(\n board: InstalledBoard,\n phase: string,\n facts: RuleFacts,\n carriesPullRequest = false,\n): boolean {\n const flow = boardFlow(board);\n const review = flow.pullRequestReview;\n if (!review) return true;\n if (facts['source.kind'] !== 'pull_request') {\n // A board that reviews pull requests but builds nothing (the retired Review board) holds only them.\n if (flow.build === undefined) return false;\n return phase !== review || carriesPullRequest;\n }\n return phase === review || board.phaseKind(phase) !== 'working';\n}\n\n/**\n * What an intake route can test about the issue a pull request closes: whether there is one with\n * a card, that card's phase, and whether a pull request already sits on it. `closedIssue` is the\n * card the provider rules found, read fresh; undefined when the pull request closes none.\n */\nexport function closedIssueRuleFacts(closedIssue: Pick<Card, 'stages' | 'workItem'> | undefined): RuleFacts {\n if (!closedIssue) return { 'pullRequest.closesIssue': false };\n return {\n 'pullRequest.closesIssue': true,\n ...(closedIssue.stages.length === 1 ? { 'closedIssue.phase': closedIssue.stages[0] } : {}),\n 'closedIssue.hasPullRequest': hasPullRequest(closedIssue),\n };\n}\n\nexport type IntakeRouteResolution =\n | { type: 'place'; board: string; phase: string; routeId: string }\n | { type: 'join'; phase: string | null; routeId: string };\n\n/**\n * What happens to an arrival: the first enabled route that places new cards, whose condition matches it and whose\n * target can take it. A placing route lands a new card on an installed board; one without a\n * phase, or whose phase has since gone, lands it in the board's initial phase. A joining route\n * matches only a pull request whose closed issue's card (`closedIssue`) is on the route's board;\n * the pull request joins that card, which moves to the route's phase when set. Undefined leaves\n * today's placement alone.\n */\nexport function resolveIntakeRoute(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n closedIssue?: Pick<Card, 'board'>,\n): IntakeRouteResolution | 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 if (route.target.joinClosedIssue) {\n if (facts['source.kind'] !== 'pull_request' || !closedIssue || boardForWorkItem(closedIssue) !== board.id)\n continue;\n const phase = route.target.phaseKey;\n return {\n type: 'join',\n phase: phase && board.phaseKind(phase) && !board.isTerminal(phase) ? phase : null,\n routeId: route.id,\n };\n }\n const phase = landingPhase(board, route.target.phaseKey);\n if (!placementTakesCard(board, phase, facts)) continue;\n return { type: 'place', board: board.id, phase, routeId: route.id };\n }\n return undefined;\n}\n\n/** Where a new card lands, by {@link resolveIntakeRoute}, for an arrival no route can join to a card. */\nexport function resolveIntakePlacement(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n): { board: string; phase: string; routeId: string } | undefined {\n const resolution = resolveIntakeRoute(routes, facts, registry);\n return resolution?.type === 'place'\n ? { board: resolution.board, phase: resolution.phase, routeId: resolution.routeId }\n : 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 carriesPullRequest = false,\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, phase, facts, carriesPullRequest)) continue;\n return { phase, routeId: route.id, allowWorkingPhase: route.allowWorkingPhase };\n }\n return undefined;\n}\n"],"mappings":";;;;AAeA,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,S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iBAAiB,MAAM,cAAc,KAAK,IAClC,QAAQ,MAAM;AAChC;;AAGA,SAAgB,kBACd,QACA,OACA,OACS;CACT,OAAO,OAAO,MAAK,UAAS,MAAM,OAAO,aAAa,MAAM,MAAM,MAAM,GAAG,SAAS,MAAM,IAAI,CAAC;AACjG;;;;;;;AAQA,SAAgB,kBACd,QACA,OACA,WACA,OACA,qBAAqB,OACuD;CAC5E,MAAM,QAAmB;EACvB,GAAG;EACH,cAAc,MAAM;EACpB,GAAI,MAAM,SAAS,EAAE,gBAAgB,MAAM,OAAO,IAAI,CAAC;CACzD;CACA,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,GAAG,SAAS,MAAM,IAAI,KAAK,MAAM,OAAO,aAAa,MAAM,IAAI;EAC5F,IAAI,CAAC,kBAAkB,MAAM,MAAM,KAAK,GAAG;EAC3C,MAAM,QAAQ,MAAM,OAAO,YAAY,MAAM;EAC7C,IAAI,MAAM,UAAU,KAAK,MAAM,KAAA,KAAa,CAAC,mBAAmB,OAAO,OAAO,OAAO,kBAAkB,GAAG;EAC1G,OAAO;GAAE;GAAO,SAAS,MAAM;GAAI,mBAAmB,MAAM;EAAkB;CAChF;AAEF"}
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';\nimport { boardFlow, boardForWorkItem, hasPullRequest } from './semantics.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'>;\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 changes, rebinding its\n * source 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' | 'join_on_event';\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; joinClosedIssue?: boolean }; 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.joinClosedIssue && route.on.some(event => event !== 'work_item.created')) {\n return {\n code: 'join_on_event',\n message:\n 'A route that joins a pull request to the card of the issue it closes handles only arrivals: its `on` must be `work_item.created` alone.',\n };\n }\n if (!target.phaseKey) return undefined;\n if (target.joinClosedIssue && board.phaseKind(target.phaseKey) === 'terminal') {\n return {\n code: 'terminal_phase',\n message: `Phase \"${target.phaseKey}\" on board \"${target.boardKey}\" is terminal; a card a pull request joins can't move there.`,\n };\n }\n if (target.joinClosedIssue) {\n return board.phaseKind(target.phaseKey)\n ? undefined\n : { code: 'unknown_phase', message: `Board \"${target.boardKey}\" has no phase \"${target.phaseKey}\".` };\n }\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 * On a board that reviews pull requests a pull request card works only in the pull request review\n * phase (it may also rest or finish), and nothing else lands in that review: a card arriving here\n * carries no attached pull request yet, and an existing issue card enters it only with one on it.\n * `FactoryTransitionService` refuses any move that breaks this, so a route can't either.\n */\nfunction placementTakesCard(\n board: InstalledBoard,\n phase: string,\n facts: RuleFacts,\n carriesPullRequest = false,\n): boolean {\n const flow = boardFlow(board);\n const review = flow.pullRequestReview;\n if (!review) return true;\n if (facts['source.kind'] !== 'pull_request') {\n // A board that reviews pull requests but builds nothing (the retired Review board) holds only them.\n if (flow.build === undefined) return false;\n return phase !== review || carriesPullRequest;\n }\n return phase === review || board.phaseKind(phase) !== 'working';\n}\n\n/**\n * What an intake route can test about the issue a pull request closes: whether there is one with\n * a card, that card's phase, and whether a pull request already sits on it. `closedIssue` is the\n * card the provider rules found, read fresh; undefined when the pull request closes none.\n */\nexport function closedIssueRuleFacts(closedIssue: Pick<Card, 'stages' | 'workItem'> | undefined): RuleFacts {\n if (!closedIssue) return { 'pullRequest.closesIssue': false };\n return {\n 'pullRequest.closesIssue': true,\n ...(closedIssue.stages.length === 1 ? { 'closedIssue.phase': closedIssue.stages[0] } : {}),\n 'closedIssue.hasPullRequest': hasPullRequest(closedIssue),\n };\n}\n\nexport type IntakeRouteResolution =\n | { type: 'place'; board: string; phase: string; routeId: string }\n | { type: 'join'; phase: string | null; routeId: string };\n\n/**\n * What happens to an arrival: the first enabled route that places new cards, whose condition matches it and whose\n * target can take it. A placing route lands a new card on an installed board; one without a\n * phase, or whose phase has since gone, lands it in the board's initial phase. A joining route\n * matches only a pull request whose closed issue's card (`closedIssue`) is on the route's board;\n * the pull request joins that card, which moves to the route's phase when set. Undefined leaves\n * today's placement alone.\n */\nexport function resolveIntakeRoute(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n closedIssue?: Pick<Card, 'board'>,\n): IntakeRouteResolution | 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 if (route.target.joinClosedIssue) {\n if (facts['source.kind'] !== 'pull_request' || !closedIssue || boardForWorkItem(closedIssue) !== board.id)\n continue;\n const phase = route.target.phaseKey;\n return {\n type: 'join',\n phase: phase && board.phaseKind(phase) && !board.isTerminal(phase) ? phase : null,\n routeId: route.id,\n };\n }\n const phase = landingPhase(board, route.target.phaseKey);\n if (!placementTakesCard(board, phase, facts)) continue;\n return { type: 'place', board: board.id, phase, routeId: route.id };\n }\n return undefined;\n}\n\n/** Where a new card lands, by {@link resolveIntakeRoute}, for an arrival no route can join to a card. */\nexport function resolveIntakePlacement(\n routes: readonly IntakeRoute[],\n facts: RuleFacts,\n registry: BoardRegistry,\n): { board: string; phase: string; routeId: string } | undefined {\n const resolution = resolveIntakeRoute(routes, facts, registry);\n return resolution?.type === 'place'\n ? { board: resolution.board, phase: resolution.phase, routeId: resolution.routeId }\n : 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 IntakeRoute[],\n event: BoardEventFacts,\n cardFacts: RuleFacts,\n board: InstalledBoard,\n carriesPullRequest = false,\n): { phase: string; routeId: string } | 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, phase, facts, carriesPullRequest)) continue;\n return { phase, routeId: route.id };\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,OAAO,mBAAmB,MAAM,GAAG,MAAK,UAAS,UAAU,mBAAmB,GAChF,OAAO;EACL,MAAM;EACN,SACE;CACJ;CAEF,IAAI,CAAC,OAAO,UAAU,OAAO,KAAA;CAC7B,IAAI,OAAO,mBAAmB,MAAM,UAA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AQA,SAAgB,kBACd,QACA,OACA,WACA,OACA,qBAAqB,OAC2B;CAChD,MAAM,QAAmB;EACvB,GAAG;EACH,cAAc,MAAM;EACpB,GAAI,MAAM,SAAS,EAAE,gBAAgB,MAAM,OAAO,IAAI,CAAC;CACzD;CACA,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAAC,MAAM,WAAW,CAAC,MAAM,GAAG,SAAS,MAAM,IAAI,KAAK,MAAM,OAAO,aAAa,MAAM,IAAI;EAC5F,IAAI,CAAC,kBAAkB,MAAM,MAAM,KAAK,GAAG;EAC3C,MAAM,QAAQ,MAAM,OAAO,YAAY,MAAM;EAC7C,IAAI,MAAM,UAAU,KAAK,MAAM,KAAA,KAAa,CAAC,mBAAmB,OAAO,OAAO,OAAO,kBAAkB,GAAG;EAC1G,OAAO;GAAE;GAAO,SAAS,MAAM;EAAG;CACpC;AAEF"}
@@ -1,5 +1,8 @@
1
1
  import type { InlineSkill } from '@mastra/core/skills';
2
+ import type { FactoryStorageOps } from '@mastra/core/storage';
2
3
  import type { StoredBoardInput, StoredBoardScope, StoredBoardsStorage } from '../storage/domains/boards/base.js';
4
+ import type { RetiredAutomationSettings } from '../storage/domains/projects/base.js';
5
+ import type { WorkItemsStorage } from '../storage/domains/work-items/base.js';
3
6
  import type { BoardRegistry } from './registry.js';
4
7
  /** Where a board in a project's catalog came from. */
5
8
  export type BoardSourceKind = 'builtin' | 'app' | 'stored';
@@ -35,13 +38,22 @@ export interface ProjectBoardCacheOptions {
35
38
  /** The code boards, built-ins included when enabled. */
36
39
  codeRegistry: BoardRegistry;
37
40
  storage: StoredBoardsStorage;
38
- /** Lists every project, to warm them at boot. */
41
+ /**
42
+ * Lists every project, to warm them at boot, and reads the retired switches the board
43
+ * migrations carry into each project's boards.
44
+ */
39
45
  projects?: {
40
46
  listAll(): Promise<readonly {
41
47
  orgId: string;
42
48
  id: string;
43
49
  }[]>;
50
+ retiredAutomationSettings?(project: {
51
+ orgId: string;
52
+ id: string;
53
+ }, ops: FactoryStorageOps): Promise<RetiredAutomationSettings | null>;
44
54
  };
55
+ /** The phases cards sit in on each of the project's boards, which a board migration must not remove. */
56
+ occupiedPhases?: (scope: StoredBoardScope, ops: FactoryStorageOps) => Promise<ReadonlyMap<string, ReadonlySet<string>> | null>;
45
57
  codeSkills?: readonly InlineSkill[];
46
58
  /**
47
59
  * Whether the project still uses the retired Review board (an open card is stored on it). Such
@@ -52,6 +64,11 @@ export interface ProjectBoardCacheOptions {
52
64
  now?: () => number;
53
65
  warn?: (message: string) => void;
54
66
  }
67
+ /**
68
+ * Reads the phases cards sit in on each of a project's boards, for `occupiedPhases`. Null while
69
+ * cards from before the work-item split are still being copied: `listWith` can't see those yet.
70
+ */
71
+ export declare function occupiedPhasesOf(workItems: Pick<WorkItemsStorage, 'listWith' | 'legacyBackfillPending'>): (scope: StoredBoardScope, ops: FactoryStorageOps) => Promise<ReadonlyMap<string, ReadonlySet<string>> | null>;
55
72
  /**
56
73
  * The per-project board cache. A project's boards are its rows: the Work and app boards Factory
57
74
  * stored in it, in code order, then the others. A Work or app board's row runs with the code
@@ -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,EACV,gBAAgB,EAEhB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAI3C,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAgCnE,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,eAAe,CAAC;IACxB,+GAA+G;IAC/G,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,uGAAuG;AACvG,MAAM,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E,KAAK,IAAI,gBAAgB,EAAE,CAE1B;IAED,qGAAqG;IACrG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAEjD;IAEK,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAE1D;IAED,4GAA4G;IACtG,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAY9D;IAED;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAcjD;IAED,+CAA+C;IAC/C,IAAI,UAAU,IAAI,SAAS,WAAW,EAAE,CAEvC;IAED,oGAAoG;IACpG,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAMxC;IAED,yGAAyG;IACnG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAe7B;CA+KF"}
@@ -3,6 +3,7 @@ import "../storage/domains/boards/base.js";
3
3
  import { LEGACY_REVIEW_BOARD } from "../storage/domains/work-items/legacy-review.js";
4
4
  import { createBoardRegistry, defaultBoards } from "./registry.js";
5
5
  import { reviewBoard } from "./review.js";
6
+ import { boardForWorkItem } from "./semantics.js";
6
7
  import { boardDefinitionOf, compileStoredBoard, mergeCodeBehaviour } from "./stored-board.js";
7
8
  import { BOARD_MIGRATIONS } from "./work-migrations.js";
8
9
  // src/boards/project-boards.ts
@@ -46,6 +47,23 @@ function scopeKey(scope) {
46
47
  return `${scope.orgId}\0${scope.factoryProjectId}`;
47
48
  }
48
49
  /**
50
+ * Reads the phases cards sit in on each of a project's boards, for `occupiedPhases`. Null while
51
+ * cards from before the work-item split are still being copied: `listWith` can't see those yet.
52
+ */
53
+ function occupiedPhasesOf(workItems) {
54
+ return async (scope, ops) => {
55
+ if (workItems.legacyBackfillPending) return null;
56
+ const occupied = /* @__PURE__ */ new Map();
57
+ for (const item of await workItems.listWith(ops, scope)) {
58
+ const board = boardForWorkItem(item);
59
+ const phases = occupied.get(board) ?? /* @__PURE__ */ new Set();
60
+ for (const stage of item.stages) phases.add(stage);
61
+ occupied.set(board, phases);
62
+ }
63
+ return occupied;
64
+ };
65
+ }
66
+ /**
49
67
  * The per-project board cache. A project's boards are its rows: the Work and app boards Factory
50
68
  * stored in it, in code order, then the others. A Work or app board's row runs with the code
51
69
  * behaviour of its board and phase keys that still fits it ({@link mergeCodeBehaviour}). A project
@@ -73,10 +91,12 @@ var ProjectBoardCache = class {
73
91
  #codeSkills;
74
92
  #seeds;
75
93
  #reviewBoardInUse;
94
+ #occupiedPhases;
76
95
  constructor(options) {
77
96
  this.codeRegistry = options.codeRegistry;
78
97
  this.#storage = options.storage;
79
98
  this.#reviewBoardInUse = options.reviewBoardInUse;
99
+ this.#occupiedPhases = options.occupiedPhases;
80
100
  this.#projects = options.projects;
81
101
  this.#codeSkills = options.codeSkills ?? [];
82
102
  this.#recheckMs = options.recheckMs ?? DEFAULT_RECHECK_MS;
@@ -199,13 +219,30 @@ var ProjectBoardCache = class {
199
219
  /** Runs the board migrations of the boards Factory stores here that the project hasn't had yet. */
200
220
  async #migrate(scope) {
201
221
  const migrations = BOARD_MIGRATIONS.filter((migration) => {
222
+ if (migration.boardKey === null) return true;
202
223
  const code = this.codeRegistry.get(migration.boardKey);
203
224
  return code !== void 0 && defaultBoards.includes(code);
204
225
  });
205
- const changed = await this.#storage.applyBoardMigrations(scope, migrations);
226
+ const changed = await this.#storage.applyBoardMigrations(scope, migrations, (ops) => this.#migrationContext(scope, ops));
206
227
  if (changed.length === 0) return;
207
228
  const filled = changed.map(({ boardKey, filled }) => `${boardKey}: ${filled.join(", ")}`).join("; ");
208
- console.info(`[factory] Updated the boards of project ${scope.factoryProjectId} that still held old defaults (${filled}).`);
229
+ console.info(`[factory] Migrated the boards of project ${scope.factoryProjectId} (${filled}).`);
230
+ }
231
+ /** Read through the migration transaction's `ops`, so card moves can't slip in unseen on LibSQL. */
232
+ async #migrationContext(scope, ops) {
233
+ const retiredSettings = await this.#projects?.retiredAutomationSettings?.({
234
+ orgId: scope.orgId,
235
+ id: scope.factoryProjectId
236
+ }, ops) ?? null;
237
+ return {
238
+ retiredSettings,
239
+ occupiedPhases: retiredSettings && this.#occupiedPhases ? await this.#occupiedPhases(scope, ops) : null,
240
+ codePhases: (boardKey) => {
241
+ const code = this.codeRegistry.get(boardKey);
242
+ return code ? new Set(Object.keys(code.phases)) : void 0;
243
+ },
244
+ warn: (message) => this.#warnOnce(`migration:${scopeKey(scope)}:${message}`, `${message} (project ${scope.factoryProjectId})`)
245
+ };
209
246
  }
210
247
  #compile(scope, rows, reviewInUse) {
211
248
  const byKey = new Map(rows.map((row) => [row.key, row]));
@@ -291,6 +328,6 @@ var ProjectBoardCache = class {
291
328
  this.#warn(message);
292
329
  }
293
330
  };
294
- export { ProjectBoardCache, toBoardSource };
331
+ export { ProjectBoardCache, occupiedPhasesOf, toBoardSource };
295
332
 
296
333
  //# sourceMappingURL=project-boards.js.map