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

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 (399) hide show
  1. package/README.md +244 -123
  2. package/dist/boards/board-events.d.ts +23 -3
  3. package/dist/boards/board-events.d.ts.map +1 -1
  4. package/dist/boards/board-events.js +44 -7
  5. package/dist/boards/board-events.js.map +1 -1
  6. package/dist/boards/board-writes.d.ts +1 -1
  7. package/dist/boards/board-writes.d.ts.map +1 -1
  8. package/dist/boards/board-writes.js +16 -1
  9. package/dist/boards/board-writes.js.map +1 -1
  10. package/dist/boards/card-facts.d.ts +1 -1
  11. package/dist/boards/card-facts.d.ts.map +1 -1
  12. package/dist/boards/card-facts.js +4 -0
  13. package/dist/boards/card-facts.js.map +1 -1
  14. package/dist/boards/default-board.d.ts +7 -0
  15. package/dist/boards/default-board.d.ts.map +1 -0
  16. package/dist/boards/default-board.js +10 -0
  17. package/dist/boards/default-board.js.map +1 -0
  18. package/dist/boards/define-board.d.ts +39 -17
  19. package/dist/boards/define-board.d.ts.map +1 -1
  20. package/dist/boards/define-board.js +64 -42
  21. package/dist/boards/define-board.js.map +1 -1
  22. package/dist/boards/index.d.ts +5 -8
  23. package/dist/boards/index.d.ts.map +1 -1
  24. package/dist/boards/index.js +5 -19
  25. package/dist/boards/intake-routing.d.ts +27 -5
  26. package/dist/boards/intake-routing.d.ts.map +1 -1
  27. package/dist/boards/intake-routing.js +69 -16
  28. package/dist/boards/intake-routing.js.map +1 -1
  29. package/dist/boards/legacy-plan-role.d.ts.map +1 -1
  30. package/dist/boards/legacy-plan-role.js +7 -2
  31. package/dist/boards/legacy-plan-role.js.map +1 -1
  32. package/dist/boards/phase-automation.d.ts +7 -0
  33. package/dist/boards/phase-automation.d.ts.map +1 -1
  34. package/dist/boards/phase-automation.js +16 -5
  35. package/dist/boards/phase-automation.js.map +1 -1
  36. package/dist/boards/phase-runner.d.ts +18 -10
  37. package/dist/boards/phase-runner.d.ts.map +1 -1
  38. package/dist/boards/phase-runner.js +39 -34
  39. package/dist/boards/phase-runner.js.map +1 -1
  40. package/dist/boards/project-boards.d.ts +9 -6
  41. package/dist/boards/project-boards.d.ts.map +1 -1
  42. package/dist/boards/project-boards.js +56 -18
  43. package/dist/boards/project-boards.js.map +1 -1
  44. package/dist/boards/registry.d.ts.map +1 -1
  45. package/dist/boards/registry.js +3 -1
  46. package/dist/boards/registry.js.map +1 -1
  47. package/dist/boards/relocate.d.ts +1 -1
  48. package/dist/boards/relocate.d.ts.map +1 -1
  49. package/dist/boards/relocate.js +3 -2
  50. package/dist/boards/relocate.js.map +1 -1
  51. package/dist/boards/review.d.ts +5 -2
  52. package/dist/boards/review.d.ts.map +1 -1
  53. package/dist/boards/review.js +12 -11
  54. package/dist/boards/review.js.map +1 -1
  55. package/dist/boards/semantics.d.ts +159 -20
  56. package/dist/boards/semantics.d.ts.map +1 -1
  57. package/dist/boards/semantics.js +256 -23
  58. package/dist/boards/semantics.js.map +1 -1
  59. package/dist/boards/stored-board.d.ts +32 -18
  60. package/dist/boards/stored-board.d.ts.map +1 -1
  61. package/dist/boards/stored-board.js +31 -97
  62. package/dist/boards/stored-board.js.map +1 -1
  63. package/dist/boards/work-migrations.d.ts +19 -0
  64. package/dist/boards/work-migrations.d.ts.map +1 -0
  65. package/dist/boards/work-migrations.js +257 -0
  66. package/dist/boards/work-migrations.js.map +1 -0
  67. package/dist/boards/work-routes.d.ts +53 -0
  68. package/dist/boards/work-routes.d.ts.map +1 -0
  69. package/dist/boards/work-routes.js +256 -0
  70. package/dist/boards/work-routes.js.map +1 -0
  71. package/dist/boards/work.d.ts +8 -19
  72. package/dist/boards/work.d.ts.map +1 -1
  73. package/dist/boards/work.js +38 -270
  74. package/dist/boards/work.js.map +1 -1
  75. package/dist/factory.d.ts +3 -3
  76. package/dist/factory.d.ts.map +1 -1
  77. package/dist/factory.js +58 -30
  78. package/dist/factory.js.map +1 -1
  79. package/dist/index.d.ts +2 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +2 -3
  82. package/dist/integrations/base.d.ts +6 -2
  83. package/dist/integrations/base.d.ts.map +1 -1
  84. package/dist/integrations/closing-references.d.ts +15 -0
  85. package/dist/integrations/closing-references.d.ts.map +1 -0
  86. package/dist/integrations/closing-references.js +69 -0
  87. package/dist/integrations/closing-references.js.map +1 -0
  88. package/dist/integrations/github/default-rules.d.ts +15 -66
  89. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  90. package/dist/integrations/github/default-rules.js +129 -71
  91. package/dist/integrations/github/default-rules.js.map +1 -1
  92. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  93. package/dist/integrations/github/issue-reconciler.js +3 -1
  94. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  95. package/dist/integrations/github/pull-request-source.d.ts +8 -0
  96. package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
  97. package/dist/integrations/github/pull-request-source.js +17 -0
  98. package/dist/integrations/github/pull-request-source.js.map +1 -0
  99. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -1
  100. package/dist/integrations/github/review-status-reporter.js +7 -3
  101. package/dist/integrations/github/review-status-reporter.js.map +1 -1
  102. package/dist/integrations/github/routes.js +1 -1
  103. package/dist/integrations/github/rules.d.ts +13 -2
  104. package/dist/integrations/github/rules.d.ts.map +1 -1
  105. package/dist/integrations/github/rules.js +202 -34
  106. package/dist/integrations/github/rules.js.map +1 -1
  107. package/dist/integrations/github/session-subscriptions.js +2 -2
  108. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  109. package/dist/integrations/github/token-refresh.d.ts +2 -1
  110. package/dist/integrations/github/token-refresh.d.ts.map +1 -1
  111. package/dist/integrations/github/token-refresh.js.map +1 -1
  112. package/dist/integrations/gitlab/agent-tools.js +1 -1
  113. package/dist/integrations/gitlab/default-rules.d.ts +73 -31
  114. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  115. package/dist/integrations/gitlab/default-rules.js +106 -43
  116. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  117. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
  118. package/dist/integrations/gitlab/issue-reconciler.js +2 -1
  119. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
  120. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
  121. package/dist/integrations/gitlab/merge-request-reconciler.js +11 -4
  122. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  123. package/dist/integrations/gitlab/rules.d.ts +6 -1
  124. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  125. package/dist/integrations/gitlab/rules.js +116 -23
  126. package/dist/integrations/gitlab/rules.js.map +1 -1
  127. package/dist/integrations/gitlab/session-subscriptions.js +1 -1
  128. package/dist/integrations/incidentio/agent-tools.js +1 -1
  129. package/dist/integrations/incidentio/default-rules.js +3 -3
  130. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  131. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  132. package/dist/integrations/incidentio/issue-reconciler.js +2 -1
  133. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  134. package/dist/integrations/incidentio/rules.d.ts +3 -1
  135. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  136. package/dist/integrations/incidentio/rules.js +14 -11
  137. package/dist/integrations/incidentio/rules.js.map +1 -1
  138. package/dist/integrations/jira/agent-tools.js +1 -1
  139. package/dist/integrations/jira/default-rules.js +3 -3
  140. package/dist/integrations/jira/default-rules.js.map +1 -1
  141. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  142. package/dist/integrations/jira/issue-reconciler.js +2 -1
  143. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  144. package/dist/integrations/jira/rules.d.ts +3 -1
  145. package/dist/integrations/jira/rules.d.ts.map +1 -1
  146. package/dist/integrations/jira/rules.js +14 -11
  147. package/dist/integrations/jira/rules.js.map +1 -1
  148. package/dist/integrations/linear/agent-tools.d.ts +9 -1
  149. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  150. package/dist/integrations/linear/agent-tools.js +80 -2
  151. package/dist/integrations/linear/agent-tools.js.map +1 -1
  152. package/dist/integrations/linear/default-rules.js +3 -3
  153. package/dist/integrations/linear/default-rules.js.map +1 -1
  154. package/dist/integrations/linear/integration.d.ts +4 -1
  155. package/dist/integrations/linear/integration.d.ts.map +1 -1
  156. package/dist/integrations/linear/integration.js +21 -1
  157. package/dist/integrations/linear/integration.js.map +1 -1
  158. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
  159. package/dist/integrations/linear/issue-reconciler.js +2 -1
  160. package/dist/integrations/linear/issue-reconciler.js.map +1 -1
  161. package/dist/integrations/linear/routes.d.ts +2 -1
  162. package/dist/integrations/linear/routes.d.ts.map +1 -1
  163. package/dist/integrations/linear/routes.js +4 -3
  164. package/dist/integrations/linear/routes.js.map +1 -1
  165. package/dist/integrations/linear/rules.d.ts +3 -1
  166. package/dist/integrations/linear/rules.d.ts.map +1 -1
  167. package/dist/integrations/linear/rules.js +15 -12
  168. package/dist/integrations/linear/rules.js.map +1 -1
  169. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  170. package/dist/integrations/platform/github/integration.js +33 -21
  171. package/dist/integrations/platform/github/integration.js.map +1 -1
  172. package/dist/integrations/platform/jira/agent-tools.js +1 -1
  173. package/dist/integrations/platform/linear/integration.d.ts +1 -1
  174. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  175. package/dist/integrations/platform/linear/integration.js +6 -5
  176. package/dist/integrations/platform/linear/integration.js.map +1 -1
  177. package/dist/integrations/slack/chat-tools.js +1 -1
  178. package/dist/integrations/slack/reply-tool.js +1 -1
  179. package/dist/integrations/slack/share-file-tool.js +1 -1
  180. package/dist/integrations/slack/slack.d.ts +10 -4
  181. package/dist/integrations/slack/slack.d.ts.map +1 -1
  182. package/dist/integrations/slack/slack.js +19 -9
  183. package/dist/integrations/slack/slack.js.map +1 -1
  184. package/dist/links.d.ts.map +1 -1
  185. package/dist/links.js +3 -2
  186. package/dist/links.js.map +1 -1
  187. package/dist/mcp/routes.js +2 -2
  188. package/dist/routes/attention-parked.d.ts +1 -0
  189. package/dist/routes/attention-parked.d.ts.map +1 -1
  190. package/dist/routes/attention-parked.js +1 -1
  191. package/dist/routes/attention-parked.js.map +1 -1
  192. package/dist/routes/automation-runs.d.ts +4 -0
  193. package/dist/routes/automation-runs.d.ts.map +1 -1
  194. package/dist/routes/automation-runs.js +15 -0
  195. package/dist/routes/automation-runs.js.map +1 -1
  196. package/dist/routes/boards.d.ts +1 -1
  197. package/dist/routes/boards.d.ts.map +1 -1
  198. package/dist/routes/boards.js +1 -17
  199. package/dist/routes/boards.js.map +1 -1
  200. package/dist/routes/config.d.ts +4 -0
  201. package/dist/routes/config.d.ts.map +1 -1
  202. package/dist/routes/config.js +15 -0
  203. package/dist/routes/config.js.map +1 -1
  204. package/dist/routes/contracts.d.ts +125 -14
  205. package/dist/routes/contracts.d.ts.map +1 -1
  206. package/dist/routes/contracts.js +34 -15
  207. package/dist/routes/contracts.js.map +1 -1
  208. package/dist/routes/fs.d.ts +4 -0
  209. package/dist/routes/fs.d.ts.map +1 -1
  210. package/dist/routes/fs.js +8 -4
  211. package/dist/routes/fs.js.map +1 -1
  212. package/dist/routes/intake-routes.d.ts.map +1 -1
  213. package/dist/routes/intake-routes.js.map +1 -1
  214. package/dist/routes/intake.d.ts.map +1 -1
  215. package/dist/routes/intake.js +1 -0
  216. package/dist/routes/intake.js.map +1 -1
  217. package/dist/routes/projects.d.ts.map +1 -1
  218. package/dist/routes/projects.js +8 -2
  219. package/dist/routes/projects.js.map +1 -1
  220. package/dist/routes/provider-credentials.d.ts.map +1 -1
  221. package/dist/routes/provider-credentials.js +10 -5
  222. package/dist/routes/provider-credentials.js.map +1 -1
  223. package/dist/routes/running-packages.d.ts +13 -0
  224. package/dist/routes/running-packages.d.ts.map +1 -0
  225. package/dist/routes/running-packages.js +45 -0
  226. package/dist/routes/running-packages.js.map +1 -0
  227. package/dist/routes/surface.d.ts +10 -1
  228. package/dist/routes/surface.d.ts.map +1 -1
  229. package/dist/routes/surface.js +104 -35
  230. package/dist/routes/surface.js.map +1 -1
  231. package/dist/routes/work-items.d.ts.map +1 -1
  232. package/dist/routes/work-items.js +23 -3
  233. package/dist/routes/work-items.js.map +1 -1
  234. package/dist/rules/binding-context.d.ts.map +1 -1
  235. package/dist/rules/binding-context.js +1 -0
  236. package/dist/rules/binding-context.js.map +1 -1
  237. package/dist/rules/dispatcher.d.ts +0 -1
  238. package/dist/rules/dispatcher.d.ts.map +1 -1
  239. package/dist/rules/dispatcher.js +340 -42
  240. package/dist/rules/dispatcher.js.map +1 -1
  241. package/dist/rules/event-rules.d.ts +33 -2
  242. package/dist/rules/event-rules.d.ts.map +1 -1
  243. package/dist/rules/event-rules.js +46 -11
  244. package/dist/rules/event-rules.js.map +1 -1
  245. package/dist/rules/index.d.ts +2 -4
  246. package/dist/rules/index.d.ts.map +1 -1
  247. package/dist/rules/index.js +2 -3
  248. package/dist/rules/phase-goal.d.ts +54 -0
  249. package/dist/rules/phase-goal.d.ts.map +1 -0
  250. package/dist/rules/phase-goal.js +70 -0
  251. package/dist/rules/phase-goal.js.map +1 -0
  252. package/dist/rules/phase-tools.d.ts +11 -0
  253. package/dist/rules/phase-tools.d.ts.map +1 -0
  254. package/dist/rules/phase-tools.js +19 -0
  255. package/dist/rules/phase-tools.js.map +1 -0
  256. package/dist/rules/processor.d.ts.map +1 -1
  257. package/dist/rules/processor.js +112 -11
  258. package/dist/rules/processor.js.map +1 -1
  259. package/dist/rules/review-source-tool.d.ts +4 -1
  260. package/dist/rules/review-source-tool.d.ts.map +1 -1
  261. package/dist/rules/review-source-tool.js +24 -4
  262. package/dist/rules/review-source-tool.js.map +1 -1
  263. package/dist/rules/rule-group.d.ts +1 -1
  264. package/dist/rules/rule-group.d.ts.map +1 -1
  265. package/dist/rules/rule-group.js +2 -1
  266. package/dist/rules/rule-group.js.map +1 -1
  267. package/dist/rules/start-coordinator.d.ts +5 -1
  268. package/dist/rules/start-coordinator.d.ts.map +1 -1
  269. package/dist/rules/start-coordinator.js +9 -3
  270. package/dist/rules/start-coordinator.js.map +1 -1
  271. package/dist/rules/tools.d.ts.map +1 -1
  272. package/dist/rules/tools.js +39 -28
  273. package/dist/rules/tools.js.map +1 -1
  274. package/dist/rules/transition-service.d.ts +2 -7
  275. package/dist/rules/transition-service.d.ts.map +1 -1
  276. package/dist/rules/transition-service.js +61 -54
  277. package/dist/rules/transition-service.js.map +1 -1
  278. package/dist/rules/types.d.ts +83 -29
  279. package/dist/rules/types.d.ts.map +1 -1
  280. package/dist/rules/types.js +5 -41
  281. package/dist/rules/types.js.map +1 -1
  282. package/dist/rules/validation.d.ts.map +1 -1
  283. package/dist/rules/validation.js +32 -2
  284. package/dist/rules/validation.js.map +1 -1
  285. package/dist/secret-encryption.d.ts +21 -0
  286. package/dist/secret-encryption.d.ts.map +1 -1
  287. package/dist/secret-encryption.js +31 -4
  288. package/dist/secret-encryption.js.map +1 -1
  289. package/dist/session/self-review-gate.d.ts +6 -2
  290. package/dist/session/self-review-gate.d.ts.map +1 -1
  291. package/dist/session/self-review-gate.js +8 -4
  292. package/dist/session/self-review-gate.js.map +1 -1
  293. package/dist/session/session-threads.d.ts +2 -3
  294. package/dist/session/session-threads.d.ts.map +1 -1
  295. package/dist/session/session-threads.js.map +1 -1
  296. package/dist/session/source-control-tools.js +1 -1
  297. package/dist/session/work-item-state-processor.d.ts +27 -0
  298. package/dist/session/work-item-state-processor.d.ts.map +1 -0
  299. package/dist/session/work-item-state-processor.js +288 -0
  300. package/dist/session/work-item-state-processor.js.map +1 -0
  301. package/dist/storage/domains/boards/base.d.ts +44 -27
  302. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  303. package/dist/storage/domains/boards/base.js +76 -121
  304. package/dist/storage/domains/boards/base.js.map +1 -1
  305. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  306. package/dist/storage/domains/boards/schemas.js +12 -0
  307. package/dist/storage/domains/boards/schemas.js.map +1 -1
  308. package/dist/storage/domains/work-items/base.d.ts +32 -2
  309. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  310. package/dist/storage/domains/work-items/base.js +109 -26
  311. package/dist/storage/domains/work-items/base.js.map +1 -1
  312. package/dist/storage/domains/work-items/cards.d.ts +24 -2
  313. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  314. package/dist/storage/domains/work-items/cards.js +118 -8
  315. package/dist/storage/domains/work-items/cards.js.map +1 -1
  316. package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
  317. package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
  318. package/dist/storage/domains/work-items/legacy-review.js +95 -0
  319. package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
  320. package/dist/storage/domains/work-items/metrics.d.ts +12 -4
  321. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  322. package/dist/storage/domains/work-items/metrics.js +14 -32
  323. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  324. package/dist/storage/domains/work-items/work-item-schema.d.ts +2 -0
  325. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  326. package/dist/storage/domains/work-items/work-item-schema.js +5 -0
  327. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  328. package/dist/tools/approval-tools.d.ts.map +1 -1
  329. package/dist/tools/approval-tools.js +28 -9
  330. package/dist/tools/approval-tools.js.map +1 -1
  331. package/dist/tools/index.d.ts +1 -1
  332. package/dist/tools/index.js +1 -1
  333. package/dist/tools/index.js.map +1 -1
  334. package/dist/tools/messaging-tools.d.ts +3 -0
  335. package/dist/tools/messaging-tools.d.ts.map +1 -1
  336. package/dist/tools/messaging-tools.js +2 -1
  337. package/dist/tools/messaging-tools.js.map +1 -1
  338. package/dist/tools/read-tools.d.ts +8 -2
  339. package/dist/tools/read-tools.d.ts.map +1 -1
  340. package/dist/tools/read-tools.js +83 -23
  341. package/dist/tools/read-tools.js.map +1 -1
  342. package/dist/tools/reports.d.ts +1 -0
  343. package/dist/tools/reports.d.ts.map +1 -1
  344. package/dist/tools/reports.js +2 -1
  345. package/dist/tools/reports.js.map +1 -1
  346. package/dist/tools/run-watch.d.ts +1 -1
  347. package/dist/tools/run-watch.d.ts.map +1 -1
  348. package/dist/tools/run-watch.js +1 -0
  349. package/dist/tools/run-watch.js.map +1 -1
  350. package/dist/tools/sandbox-tools.js +1 -1
  351. package/dist/tools/session-tools.js +1 -1
  352. package/dist/tools/sessions-state-processor.d.ts +2 -0
  353. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  354. package/dist/tools/sessions-state-processor.js +4 -2
  355. package/dist/tools/sessions-state-processor.js.map +1 -1
  356. package/dist/tools/side-sessions.d.ts +2 -0
  357. package/dist/tools/side-sessions.d.ts.map +1 -1
  358. package/dist/tools/side-sessions.js +2 -1
  359. package/dist/tools/side-sessions.js.map +1 -1
  360. package/dist/tools/work-item-tools.js +3 -3
  361. package/dist/tools/work-item-tools.js.map +1 -1
  362. package/dist/work-item-branch.d.ts +13 -0
  363. package/dist/work-item-branch.d.ts.map +1 -1
  364. package/dist/work-item-branch.js +16 -1
  365. package/dist/work-item-branch.js.map +1 -1
  366. package/dist/work-items/create-work-item.d.ts +6 -0
  367. package/dist/work-items/create-work-item.d.ts.map +1 -1
  368. package/dist/work-items/create-work-item.js +25 -1
  369. package/dist/work-items/create-work-item.js.map +1 -1
  370. package/dist/work-items/split-migration.d.ts.map +1 -1
  371. package/dist/work-items/split-migration.js +1 -0
  372. package/dist/work-items/split-migration.js.map +1 -1
  373. package/dist/workspace.d.ts.map +1 -1
  374. package/dist/workspace.js +53 -10
  375. package/dist/workspace.js.map +1 -1
  376. package/factory-skills/configure-factory-rules/SKILL.md +11 -9
  377. package/factory-skills/factory-build/SKILL.md +64 -0
  378. package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
  379. package/factory-skills/factory-gitlab-review/SKILL.md +2 -2
  380. package/factory-skills/factory-plan/SKILL.md +8 -10
  381. package/factory-skills/factory-rereview/SKILL.md +3 -3
  382. package/factory-skills/factory-review/SKILL.md +14 -4
  383. package/factory-skills/factory-self-review/SKILL.md +31 -11
  384. package/factory-skills/factory-triage/SKILL.md +25 -10
  385. package/package.json +10 -10
  386. package/dist/boards/index.js.map +0 -1
  387. package/dist/boards/pull-request-review.d.ts +0 -14
  388. package/dist/boards/pull-request-review.d.ts.map +0 -1
  389. package/dist/boards/pull-request-review.js +0 -81
  390. package/dist/boards/pull-request-review.js.map +0 -1
  391. package/dist/boards/work-tool-rules.d.ts +0 -8
  392. package/dist/boards/work-tool-rules.d.ts.map +0 -1
  393. package/dist/boards/work-tool-rules.js +0 -19
  394. package/dist/boards/work-tool-rules.js.map +0 -1
  395. package/dist/rules/resolve.d.ts +0 -15
  396. package/dist/rules/resolve.d.ts.map +0 -1
  397. package/dist/rules/resolve.js +0 -22
  398. package/dist/rules/resolve.js.map +0 -1
  399. package/factory-skills/factory-complete-issue/SKILL.md +0 -24
@@ -1 +1 @@
1
- {"version":3,"file":"semantics.js","names":[],"sources":["../../src/boards/semantics.ts"],"sourcesContent":["import type { FactoryRuleBoardClosure, FactoryRulePhaseContext } from '../rules/types.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport type {\n BoardEventIntegration,\n BoardEventRules,\n BoardPhaseKind,\n BoardToolResultRuleHandler,\n} from './define-board.js';\nimport type { BoardRegistry } from './registry.js';\n\nexport interface PhaseSemantics {\n readonly kind: BoardPhaseKind;\n /** Seat that carries a working phase; absent for resting and terminal phases. */\n readonly role?: string;\n}\n\n/**\n * Board that owns a work item. Rows created before boards were persisted carry no `board`;\n * they belong to Review when they track a pull request and to Work otherwise, matching the\n * legacy assignment the transition service performs on their next move.\n */\nexport function boardForWorkItem(item: Pick<Card, 'board' | 'externalSource'>): string {\n return item.board ?? (item.externalSource?.type === 'pull-request' ? 'review' : 'work');\n}\n\n/**\n * A card that tracks a pull or merge request itself, as opposed to the card whose work opened it.\n * Both can sit on Work, so rules tell them apart by source rather than by board.\n */\nexport function isPullRequestCard(item: { readonly source: string }): boolean {\n return item.source === 'github-pr' || item.source === 'gitlab-pr';\n}\n\n/** Whether the rule's card is the change request's own card, which the reviewer reviews. */\nexport function reviewsPullRequest(context: {\n readonly board?: string;\n readonly item?: { readonly source: string };\n}): boolean {\n if (context.board === 'review') return true;\n return context.board === 'work' && context.item !== undefined && isPullRequestCard(context.item);\n}\n\n/**\n * The phase a pull or merge request's own card is reviewed in: Work's `pr-review`, or Review's\n * `review` for cards filed on the Review board before pull requests moved to Work. Work's own\n * `review` phase is the builder's self-review, which a pull request card never enters.\n */\nexport function pullRequestReviewPhase(board: string | undefined): 'review' | 'pr-review' {\n return board === 'review' ? 'review' : 'pr-review';\n}\n\n/**\n * What the installed board says `phase` means. Returns undefined when the board is not\n * installed or does not declare the phase; callers must fail closed on undefined rather\n * than guess from the phase name.\n */\nexport function resolvePhaseSemantics(\n boards: BoardRegistry,\n boardId: string,\n phase: string,\n): PhaseSemantics | undefined {\n const board = boards.get(boardId);\n const kind = board?.phaseKind(phase);\n if (!board || !kind) return undefined;\n const role = board.roleForPhase(phase);\n return role === undefined ? { kind } : { kind, role };\n}\n\n/**\n * Tool-result rule the installed board declares for `toolName`. Undefined when the board is\n * not installed or declares no rule for the tool; callers must run nothing in that case.\n */\nexport function resolveBoardToolRule(\n boards: BoardRegistry,\n boardId: string,\n toolName: string,\n): BoardToolResultRuleHandler | undefined {\n return boards.get(boardId)?.tools[toolName]?.onResult;\n}\n\n/**\n * Integration event handlers the installed board declares for cards on it, or undefined when the\n * card is unbound, the board is not installed, or it declares none for this integration. Within the\n * map, `null` means the board switched that event off for its cards.\n */\nexport function boardEventHandlers<I extends BoardEventIntegration>(\n boards: Pick<BoardRegistry, 'get'>,\n boardId: string | undefined,\n integration: I,\n): BoardEventRules[I] | undefined {\n return boardId === undefined ? undefined : boards.get(boardId)?.events[integration];\n}\n\n/**\n * Board whose event handlers answer an integration evaluation: the bound card's board, except on\n * the evaluation that files a pull request's own Review card, which is about a card that does\n * not exist yet.\n */\nexport function eventBoardId(context: {\n readonly item?: unknown;\n readonly board?: string;\n readonly pullRequestIntake?: boolean;\n}): string | undefined {\n return context.item && !context.pullRequestIntake ? context.board : undefined;\n}\n\n/** What a card's single current phase means on its installed board, for integration rule contexts. */\nexport function rulePhaseContext(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): FactoryRulePhaseContext | undefined {\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n if (!stage) return undefined;\n const board = boards.get(boardForWorkItem(item));\n const kind = board?.phaseKind(stage);\n if (!board || !kind) return undefined;\n const context = board.roleForPhase(stage);\n const phase = board.phases[stage];\n return Object.freeze({\n id: stage,\n kind,\n ...(context === undefined ? {} : { context, role: context }),\n nextPhases: Object.freeze([...(phase?.nextPhases ?? [])]),\n outcomes: Object.freeze(Object.keys(phase?.outcomes ?? {})),\n });\n}\n\n/**\n * Whether a persisted card has finished, judged by the board it sits on: the installed\n * board's phase kind first, then the built-in Work and Review names for rows whose board is\n * not installed. Unknown boards or phases are never terminal, so a card is only ever\n * released from ownership on the board's own say-so.\n */\nexport function isTerminalWorkItem(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): boolean {\n const semantics = workItemPhaseSemantics(boards, item);\n if (semantics) return semantics.kind === 'terminal';\n const board = boardForWorkItem(item);\n if (board !== 'work' && board !== 'review') return false;\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n return stage === 'done' || stage === 'canceled';\n}\n\n/** Semantics of the single stage a work item currently occupies; undefined for multi-stage rows. */\nexport function workItemPhaseSemantics(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): PhaseSemantics | undefined {\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n if (!stage) return undefined;\n return resolvePhaseSemantics(boards, boardForWorkItem(item), stage);\n}\n\n/**\n * Where source-closed rules send a persisted card: the `sourceClosed` mapping its installed\n * board declares, plus whether the card already sits in a terminal phase. Undefined when the\n * board is not installed or declares no mapping, so closing the source leaves the card alone.\n */\nexport function resolveBoardClosure(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): FactoryRuleBoardClosure | undefined {\n const board = boards.get(boardForWorkItem(item));\n if (!board?.sourceClosed) return undefined;\n const { completed, canceled } = board.sourceClosed;\n return {\n boardTitle: board.name,\n completed: { phase: completed, title: board.phases[completed]!.name },\n canceled: { phase: canceled, title: board.phases[canceled]!.name },\n itemTerminal: item.stages.some(stage => board.isTerminal(stage)),\n };\n}\n\n/** Rule-context fragment carrying the card's `boardClosure`, empty when the board declares none. */\nexport function withBoardClosure(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): { boardClosure?: FactoryRuleBoardClosure } {\n const boardClosure = resolveBoardClosure(boards, item);\n return boardClosure ? { boardClosure } : {};\n}\n\n/** `{ phase }` for spreading into an integration rule context, or `{}` when the phase is unknown. */\nexport function rulePhaseField(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): { readonly phase?: FactoryRulePhaseContext } {\n const phase = rulePhaseContext(boards, item);\n return phase ? { phase } : {};\n}\n"],"mappings":";;;;;;AAqBA,SAAgB,iBAAiB,MAAsD;CACrF,OAAO,KAAK,UAAU,KAAK,gBAAgB,SAAS,iBAAiB,WAAW;AAClF;;;;;AAMA,SAAgB,kBAAkB,MAA4C;CAC5E,OAAO,KAAK,WAAW,eAAe,KAAK,WAAW;AACxD;;AAGA,SAAgB,mBAAmB,SAGvB;CACV,IAAI,QAAQ,UAAU,UAAU,OAAO;CACvC,OAAO,QAAQ,UAAU,UAAU,QAAQ,SAAS,KAAA,KAAa,kBAAkB,QAAQ,IAAI;AACjG;;;;;;AAOA,SAAgB,uBAAuB,OAAmD;CACxF,OAAO,UAAU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actoryRuleBoardFlow,\n FactoryRuleIntakeTarget,\n FactoryRulePhaseContext,\n} from '../rules/types.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport type { MetricsPhaseOutcomes } from '../storage/domains/work-items/metrics.js';\nimport type { WorkItemSourceRow } from '../storage/domains/work-items/work-item-schema.js';\nimport { workItemBranch, workItemBranchSource } from '../work-item-branch.js';\nimport { DEFAULT_BOARD_ID } from './default-board.js';\nimport { REVIEW_CONTEXT } from './define-board.js';\nimport type {\n BoardEventIntegration,\n BoardEventRules,\n BoardPhase,\n BoardPhaseKind,\n BoardToolResultRuleHandler,\n} from './define-board.js';\nimport type { BoardRegistry, InstalledBoard } from './registry.js';\nimport { reviewBoard } from './review.js';\nimport { workBoard } from './work.js';\n\nexport interface PhaseSemantics {\n readonly kind: BoardPhaseKind;\n /** Seat that carries a working phase; absent for resting and terminal phases. */\n readonly role?: string;\n}\n\n/**\n * Board that owns a work item. Rows created before boards were persisted carry no `board`;\n * they belong to the default board. (Pull requests used to default to the retired Review board;\n * storage reads those rows as the default board, and keeps cards stored on Review there only in a\n * project that still uses it.)\n */\nexport function boardForWorkItem(item: Pick<Card, 'board'>): string {\n return item.board ?? DEFAULT_BOARD_ID;\n}\n\nconst flows = new WeakMap<object, FactoryRuleBoardFlow>();\n\n/**\n * The phases a board's pull request loop runs through, read from what each phase declares\n * rather than from its key:\n *\n * Only phases running in the {@link REVIEW_CONTEXT} seat count as reviews: it is the only seat\n * that records verdicts.\n *\n * - `pullRequestReview`: the first phase that grants `factory_review_source`. It takes pull\n * requests: a pull request's own card is reviewed there, an attached pull request is reviewed\n * there, verdicts on pull requests are recorded there, and a push or review request re-enters it.\n * - `selfReview`: the first working phase that grants `factory_record_review_verdict` without\n * `factory_review_source`: an independent review of the builder's branch before a pull request.\n * - `triage`: on a board with a `build` phase, the first working phase that neither builds (runs\n * in `buildRole`) nor reviews: it sorts new cards before anyone accepts them. A board that\n * builds nothing has no triage phase.\n * - `build`: the last working phase, in declaration order, that is neither of those and can move\n * into the review that follows it (`selfReview`, else `pullRequestReview`). Self-review sends\n * requested changes back here, and its seat (`buildRole`) is woken by pull request feedback.\n *\n * A board without a `factory_review_source` phase has no pull request loop.\n */\nexport function boardFlow(board: InstalledBoard | undefined): FactoryRuleBoardFlow {\n if (!board) return Object.freeze({});\n const cached = flows.get(board);\n if (cached) return cached;\n const entries = Object.entries(board.phases) as [string, BoardPhase<string>][];\n const grants = (phase: BoardPhase<string>, tool: string) =>\n phase.kind === 'working' &&\n phase.runner.context === REVIEW_CONTEXT &&\n (phase.tools ?? []).some(granted => granted === tool);\n const pullRequestReview = entries.find(([, phase]) => grants(phase, 'factory_review_source'))?.[0];\n const selfReview = entries.find(\n ([key, phase]) =>\n key !== pullRequestReview &&\n grants(phase, 'factory_record_review_verdict') &&\n !grants(phase, 'factory_review_source'),\n )?.[0];\n const handoff = selfReview ?? pullRequestReview;\n const build = handoff\n ? entries.findLast(\n ([key, phase]) =>\n phase.kind === 'working' &&\n key !== pullRequestReview &&\n key !== selfReview &&\n board.allowsTransition(key, handoff),\n )?.[0]\n : undefined;\n const buildRole = build ? board.roleForPhase(build) : undefined;\n // Only a board that builds sorts cards first; elsewhere a working phase is just its own step.\n const triage = build\n ? entries.find(\n ([key, phase]) =>\n phase.kind === 'working' &&\n key !== build &&\n phase.runner.context !== REVIEW_CONTEXT &&\n phase.runner.context !== buildRole,\n )?.[0]\n : undefined;\n const terminals = entries.filter(([, phase]) => phase.kind === 'terminal').map(([key]) => key);\n const completed = board.sourceClosed?.completed ?? terminals[0];\n const canceled = board.sourceClosed?.canceled ?? terminals.find(key => key !== completed) ?? completed;\n const ref = (phase: string) => Object.freeze({ phase, title: board.phases[phase]!.name });\n const flow = Object.freeze({\n initialPhase: board.initialPhase,\n ...(completed ? { completed: ref(completed) } : {}),\n ...(canceled ? { canceled: ref(canceled) } : {}),\n ...(triage ? { triage } : {}),\n ...(pullRequestReview ? { pullRequestReview } : {}),\n ...(selfReview ? { selfReview } : {}),\n ...(build ? { build } : {}),\n ...(buildRole ? { buildRole } : {}),\n });\n flows.set(board, flow);\n return flow;\n}\n\n/**\n * Where new items land on `board`, else on the project's default board when `board` is not\n * installed. Undefined when neither is.\n */\nexport function intakeTarget(\n boards: Pick<BoardRegistry, 'get'>,\n board?: InstalledBoard,\n): FactoryRuleIntakeTarget | undefined {\n const target = board ?? boards.get(DEFAULT_BOARD_ID);\n if (!target) return undefined;\n const { pullRequestReview } = boardFlow(target);\n return Object.freeze({\n board: target.id,\n initialPhase: target.initialPhase,\n ...(pullRequestReview ? { pullRequestReview } : {}),\n });\n}\n\n/** {@link intakeTarget} as a rule context field. */\nexport function withIntakeTarget(\n boards: Pick<BoardRegistry, 'get'>,\n board?: InstalledBoard,\n): { intake?: FactoryRuleIntakeTarget } {\n const intake = intakeTarget(boards, board);\n return intake ? { intake } : {};\n}\n\n/** {@link boardFlow} of the board a card sits on. */\nexport function cardBoardFlow(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board'> | undefined,\n): FactoryRuleBoardFlow {\n return item ? boardFlow(boards.get(boardForWorkItem(item))) : Object.freeze({});\n}\n\n/**\n * Whether a card in `stage` is still waiting for someone to accept it: it rests, or it is being\n * triaged. Approval labels hold only such cards.\n */\nexport function awaitsAcceptance(board: InstalledBoard | undefined, stage: string): boolean {\n if (!board) return false;\n return board.phaseKind(stage) === 'resting' || stage === boardFlow(board).triage;\n}\n\n/** Whether `stage` is the phase where the board reviews pull requests. */\nexport function isPullRequestReviewPhase(board: InstalledBoard | undefined, stage: string | undefined): boolean {\n const phase = boardFlow(board).pullRequestReview;\n return phase !== undefined && phase === stage;\n}\n\n/**\n * Why a move breaks the shape of a card on a board with a pull request loop, or undefined when it\n * does not: a pull request's own card is only reviewed, so it enters no other working phase, and\n * the pull request review phase holds only cards that carry a pull request (their own, or one\n * attached to their issue). `nextPhases` cannot say this: a resting phase may lead to both, and\n * which one fits depends on the card.\n */\nexport function pullRequestCardRejection(\n board: InstalledBoard,\n card: { readonly standalonePullRequest: boolean; readonly hasPullRequest: boolean },\n toStage: string,\n): string | undefined {\n const review = boardFlow(board).pullRequestReview;\n if (!review) return undefined;\n const reviewName = board.phases[review]?.name ?? review;\n if (!card.hasPullRequest && toStage === review) {\n return `${reviewName} holds only cards with a pull request; this work item enters it once a pull request is attached to it.`;\n }\n if (!card.standalonePullRequest || toStage === review || !board.isWorking(toStage)) return undefined;\n const exits = [review, ...Object.keys(board.phases).filter(key => board.isTerminal(key))];\n return `A pull request card is only reviewed on the ${board.name} board; it cannot enter ${toStage}. Move it to ${exits.join(', ')}.`;\n}\n\n/** `{ flow }` for spreading into an integration rule context, or `{}` for an unbound evaluation. */\nexport function withBoardFlow(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board'> | undefined,\n): { flow?: FactoryRuleBoardFlow } {\n return item ? { flow: cardBoardFlow(boards, item) } : {};\n}\n\ninterface SourcedItem {\n readonly workItem?: { readonly sources?: readonly WorkItemSourceRow[] } | null;\n}\n\n/**\n * A card whose own primary source is a pull or merge request: an outside contributor's\n * PR filed on its own card, or a PR card filed before PRs attached to their issue's card.\n * An issue card with an attached PR is not one; see {@link hasPullRequest}.\n */\nexport function isPullRequestCard(item: { readonly source: string }): boolean {\n return item.source === 'github-pr' || item.source === 'gitlab-pr';\n}\n\n/** Every pull or merge request source on a card, oldest first. */\nexport function pullRequestSources(item: SourcedItem): WorkItemSourceRow[] {\n return (item.workItem?.sources ?? []).filter(source => source.sourceType === 'pull-request');\n}\n\n/** Whether a card carries a pull or merge request: its own, or one attached to its issue. */\nexport function hasPullRequest(item: SourcedItem & { readonly source?: string }): boolean {\n return (\n (item.source !== undefined && isPullRequestCard({ source: item.source })) || pullRequestSources(item).length > 0\n );\n}\n\n/** A source row's external id without the type/workspace scope storage prefixes it with. */\nexport function sourceExternalId(source: Pick<WorkItemSourceRow, 'sourceType' | 'workspaceId' | 'externalId'>): string {\n const prefix = `${source.sourceType}:${source.workspaceId ? `${source.workspaceId}:` : ''}`;\n return source.externalId.startsWith(prefix) ? source.externalId.slice(prefix.length) : source.externalId;\n}\n\n/** The provider number (GitHub PR number, GitLab MR IID) a pull request source names. */\nexport function pullRequestSourceNumber(source: Pick<WorkItemSourceRow, 'metadata'>): number | undefined {\n const metadata = source.metadata ?? {};\n const value = metadata.githubPullRequestNumber ?? metadata.gitlabMergeRequestIid ?? metadata.number;\n return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\nfunction openSource(source: Pick<WorkItemSourceRow, 'state' | 'metadata'>): boolean {\n const state = source.state ?? source.metadata?.state;\n return state !== 'closed' && state !== 'merged' && source.metadata?.merged !== true;\n}\n\n/**\n * The pull request a PR review pass on this card reviews: the one the card's\n * `openPullRequestNumber` names, else the newest open one, else the newest one.\n */\nexport function reviewedPullRequest(\n item: SourcedItem & { readonly metadata?: Record<string, unknown> | null },\n): WorkItemSourceRow | undefined {\n const sources = pullRequestSources(item);\n const pointer = item.metadata?.openPullRequestNumber;\n return (\n (typeof pointer === 'number' ? sources.find(source => pullRequestSourceNumber(source) === pointer) : undefined) ??\n sources.findLast(openSource) ??\n sources.at(-1)\n );\n}\n\n/** The newest still-open pull request on a card other than `except`, for re-pointing `openPullRequestNumber`. */\nexport function newestOpenPullRequestNumber(item: SourcedItem, except?: number): number | null {\n const open = pullRequestSources(item).filter(\n source => openSource(source) && pullRequestSourceNumber(source) !== except,\n );\n return (open.length ? pullRequestSourceNumber(open.at(-1)!) : undefined) ?? null;\n}\n\ninterface SessionedItem {\n readonly sessions: Readonly<Record<string, { readonly branch?: string | null } | undefined>>;\n}\n\ntype BranchedItem = Pick<Card, 'id' | 'externalSource'> & { readonly workItem: Pick<Card['workItem'], 'metadata'> };\n\n/**\n * Whether a pull request from `headBranch` was opened by the card's own sessions: the head is\n * one of its session branches, or the branch Factory builds the card on (stable even after its\n * session is deleted).\n */\nexport function cardOwnsBranch(item: SessionedItem & BranchedItem, headBranch: string | undefined): boolean {\n if (!headBranch) return false;\n const buildBranch = workItemBranch({\n id: item.id,\n source: workItemBranchSource(item.externalSource),\n metadata: item.workItem.metadata,\n });\n return buildBranch === headBranch || Object.values(item.sessions).some(session => session?.branch === headBranch);\n}\n\n/** The newest open pull request the card's own sessions opened, other than `except`. */\nexport function newestOwnedOpenPullRequestNumber(\n item: SourcedItem & SessionedItem & BranchedItem,\n except?: number,\n): number | null {\n const open = pullRequestSources(item).filter(\n source =>\n openSource(source) &&\n pullRequestSourceNumber(source) !== except &&\n typeof source.metadata?.headBranch === 'string' &&\n cardOwnsBranch(item, source.metadata.headBranch),\n );\n return (open.length ? pullRequestSourceNumber(open.at(-1)!) : undefined) ?? null;\n}\n\n/** The pull or merge request a card's PR review covers, whichever card shape carries it. */\nexport interface ReviewedChangeRequest {\n readonly provider: 'github' | 'gitlab';\n readonly number: number | undefined;\n readonly url: string | null;\n readonly headBranch: string | undefined;\n /** The card is the change request's own card rather than an issue card it is attached to. */\n readonly standalone: boolean;\n}\n\n/**\n * What a PR review on this card reviews: the card's own change request when the card is one,\n * otherwise the attached one {@link reviewedPullRequest} picks. Undefined for a card with none.\n */\nexport function reviewedChangeRequest(item: {\n readonly source: string;\n readonly url?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly workItem: {\n readonly url?: string | null;\n readonly metadata?: Record<string, unknown> | null;\n readonly sources?: readonly WorkItemSourceRow[];\n };\n}): ReviewedChangeRequest | undefined {\n if (isPullRequestCard(item)) {\n const metadata = item.workItem.metadata ?? {};\n const gitlab = item.source === 'gitlab-pr';\n const value = (gitlab ? metadata.gitlabMergeRequestIid : metadata.githubPullRequestNumber) ?? metadata.number;\n return {\n provider: gitlab ? 'gitlab' : 'github',\n number: typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined,\n url: item.url ?? item.workItem.url ?? null,\n headBranch: typeof metadata.headBranch === 'string' ? metadata.headBranch : undefined,\n standalone: true,\n };\n }\n const source = reviewedPullRequest(item);\n if (!source) return undefined;\n return {\n provider: source.integrationId === 'gitlab' ? 'gitlab' : 'github',\n number: pullRequestSourceNumber(source),\n url: source.url ?? null,\n headBranch: typeof source.metadata?.headBranch === 'string' ? source.metadata.headBranch : undefined,\n standalone: false,\n };\n}\n\n/**\n * Whether a pass already recorded a verdict on `change`. An issue card can carry\n * several pull requests, so a verdict stamped for another one doesn't count; a\n * verdict with no number (a standalone card, or one stamped before verdicts named\n * their pull request) covers the card.\n */\nexport function hasRecordedVerdict(\n item: Parameters<typeof reviewedChangeRequest>[0],\n change: Pick<ReviewedChangeRequest, 'number'> | undefined = reviewedChangeRequest(item),\n): boolean {\n const covered = item.metadata?.reviewedPullRequestNumber;\n const reviewedAnother = typeof covered === 'number' && change?.number !== undefined && covered !== change.number;\n return typeof item.metadata?.reviewVerdict === 'string' && !reviewedAnother;\n}\n\n/**\n * Whether the rule's card carries a change request its board reviews: the card has one, and its\n * board has a phase that takes pull requests ({@link boardFlow}).\n */\nexport function reviewsPullRequest(context: {\n readonly flow?: Pick<FactoryRuleBoardFlow, 'pullRequestReview'>;\n readonly item?: SourcedItem & { readonly source: string };\n}): boolean {\n return context.flow?.pullRequestReview !== undefined && context.item !== undefined && hasPullRequest(context.item);\n}\n\n/**\n * What the installed board says `phase` means. Returns undefined when the board is not\n * installed or does not declare the phase; callers must fail closed on undefined rather\n * than guess from the phase name.\n */\nexport function resolvePhaseSemantics(\n boards: BoardRegistry,\n boardId: string,\n phase: string,\n): PhaseSemantics | undefined {\n const board = boards.get(boardId);\n const kind = board?.phaseKind(phase);\n if (!board || !kind) return undefined;\n const role = board.roleForPhase(phase);\n return role === undefined ? { kind } : { kind, role };\n}\n\n/**\n * Tool-result rule the installed board declares for `toolName`. Undefined when the board is\n * not installed or declares no rule for the tool; callers must run nothing in that case.\n */\nexport function resolveBoardToolRule(\n boards: BoardRegistry,\n boardId: string,\n toolName: string,\n): BoardToolResultRuleHandler | undefined {\n return boards.get(boardId)?.tools[toolName]?.onResult;\n}\n\n/**\n * Integration event handlers the installed board declares for cards on it, or undefined when the\n * card is unbound, the board is not installed, or it declares none for this integration. Within the\n * map, `null` means the board switched that event off for its cards.\n */\nexport function boardEventHandlers<I extends BoardEventIntegration>(\n boards: Pick<BoardRegistry, 'get'>,\n boardId: string | undefined,\n integration: I,\n): BoardEventRules[I] | undefined {\n return boardId === undefined ? undefined : boards.get(boardId)?.events[integration];\n}\n\n/**\n * Board whose event handlers answer an integration evaluation: the bound card's board, except on\n * the evaluation that files a pull request's own Review card, which is about a card that does\n * not exist yet.\n */\nexport function eventBoardId(context: {\n readonly item?: unknown;\n readonly board?: string;\n readonly pullRequestIntake?: boolean;\n}): string | undefined {\n return context.item && !context.pullRequestIntake ? context.board : undefined;\n}\n\n/** What a card's single current phase means on its installed board, for integration rule contexts. */\nexport function rulePhaseContext(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): FactoryRulePhaseContext | undefined {\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n if (!stage) return undefined;\n const board = boards.get(boardForWorkItem(item));\n const kind = board?.phaseKind(stage);\n if (!board || !kind) return undefined;\n const context = board.roleForPhase(stage);\n const phase = board.phases[stage];\n return Object.freeze({\n id: stage,\n kind,\n ...(context === undefined ? {} : { context, role: context }),\n nextPhases: Object.freeze([...(phase?.nextPhases ?? [])]),\n });\n}\n\n/**\n * Whether a persisted card has finished, judged by the board it sits on: the installed board's\n * phase kind first, then, for rows whose board is not installed, the phase kinds of the default\n * board Factory seeds or of the retired Review board. Unknown boards or phases are never terminal,\n * so a card is only ever released from ownership on the board's own say-so.\n */\nexport function isTerminalWorkItem(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): boolean {\n const semantics = workItemPhaseSemantics(boards, item);\n if (semantics) return semantics.kind === 'terminal';\n const board = boardForWorkItem(item);\n if (boards.has(board)) return false;\n const seed = board === DEFAULT_BOARD_ID ? workBoard : board === reviewBoard.id ? reviewBoard : undefined;\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n return stage !== undefined && seed !== undefined && seed.isTerminal(stage);\n}\n\n/** Semantics of the single stage a work item currently occupies; undefined for multi-stage rows. */\nexport function workItemPhaseSemantics(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): PhaseSemantics | undefined {\n const stage = item.stages.length === 1 ? item.stages[0] : undefined;\n if (!stage) return undefined;\n return resolvePhaseSemantics(boards, boardForWorkItem(item), stage);\n}\n\n/**\n * Flow-metric outcomes of each board's phases: the phase the board closes completed sources into\n * (else its first terminal phase) completes a card, other terminal phases cancel it, resting\n * phases queue it, and anything else (working, or a phase the board no longer declares) is in\n * flight.\n */\nexport function boardPhaseOutcomes(boards: Pick<BoardRegistry, 'get'>): MetricsPhaseOutcomes {\n return (item, stage) => {\n const board = boards.get(boardForWorkItem(item));\n const kind = board?.phaseKind(stage);\n if (!board || kind === undefined || kind === 'working') return 'pipeline';\n if (kind === 'resting') return 'queued';\n const completed = board.sourceClosed?.completed ?? Object.keys(board.phases).find(key => board.isTerminal(key));\n return stage === completed ? 'completed' : 'canceled';\n };\n}\n\n/**\n * Where source-closed rules send a persisted card: the `sourceClosed` mapping its installed\n * board declares, plus whether the card already sits in a terminal phase. Undefined when the\n * board is not installed or declares no mapping, so closing the source leaves the card alone.\n */\nexport function resolveBoardClosure(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): FactoryRuleBoardClosure | undefined {\n const board = boards.get(boardForWorkItem(item));\n if (!board?.sourceClosed) return undefined;\n const { completed, canceled } = board.sourceClosed;\n return {\n boardTitle: board.name,\n completed: { phase: completed, title: board.phases[completed]!.name },\n canceled: { phase: canceled, title: board.phases[canceled]!.name },\n itemTerminal: item.stages.some(stage => board.isTerminal(stage)),\n };\n}\n\n/** Rule-context fragment carrying the card's `boardClosure`, empty when the board declares none. */\nexport function withBoardClosure(\n boards: BoardRegistry,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): { boardClosure?: FactoryRuleBoardClosure } {\n const boardClosure = resolveBoardClosure(boards, item);\n return boardClosure ? { boardClosure } : {};\n}\n\n/** `{ phase }` for spreading into an integration rule context, or `{}` when the phase is unknown. */\nexport function rulePhaseField(\n boards: Pick<BoardRegistry, 'get'>,\n item: Pick<Card, 'board' | 'externalSource' | 'stages'>,\n): { readonly phase?: FactoryRulePhaseContext } {\n const phase = rulePhaseContext(boards, item);\n return phase ? { phase } : {};\n}\n\n/**\n * The change request a review session on this card may publish checks for: the card's own one,\n * or, for an issue card in its board's pull request review phase, the pull request attached to it.\n */\nexport function boundChangeRequestNumber(boards: Pick<BoardRegistry, 'get'>, item: Card): string | undefined {\n const source = workItemBranchSource(item.externalSource);\n const own = isPullRequestCard({ source });\n if (!own && (item.stages.length !== 1 || cardBoardFlow(boards, item).pullRequestReview !== item.stages[0])) {\n return undefined;\n }\n const number = reviewedChangeRequest({ ...item, source })?.number;\n if (number !== undefined) return String(number);\n // A GitHub key ends in its number (`github-pr:34`); a GitLab key is encoded, so its digits mean nothing.\n return source === 'github-pr' ? /(\\d+)$/.exec(item.externalSource?.externalId ?? '')?.[1] : undefined;\n}\n"],"mappings":";;;;;;;;;;;;AAmCA,SAAgB,iBAAiB,MAAmC;CAClE,OAAO,KAAK,SAAA;AACd;AAEA,MAAM,wBAAQ,IAAI,QAAsC;;;;;;;;;;;;;;;;;;;;;;AAuBxD,SAAgB,UAAU,OAAyD;CACjF,IAAI,CAAC,OAAO,OAAO,OAAO,OAAO,CAAC,CAAC;CACnC,MAAM,SAAS,MAAM,IAAI,KAAK;CAC9B,IAAI,QAAQ,OAAO;CACnB,MAAM,UAAU,OAAO,QAAQ,MAAM,MAAM;CAC3C,MAAM,UAAU,OAA2B,SACzC,MAAM,SAAS,aACf,MAAM,OAAO,YAAA,aACZ,MAAM,SAAS,CAAC,EAAA,CAAG,MAAK,YAAW,YAAY,IAAI;CACtD,MAAM,oBAAoB,QAAQ,MAAM,GAAG,WAAW,OAAO,OAAO,uBA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AsB,KAAK,OAAO,KACrG;CAEF,MAAM,SAAS,sBAAsB;EAAE,GAAG;EAAM;CAAO,CAAC,CAAC,EAAE;CAC3D,IAAI,WAAW,KAAA,GAAW,OAAO,OAAO,MAAM;CAE9C,OAAO,WAAW,cAAc,SAAS,KAAK,KAAK,gBAAgB,cAAc,EAAE,CAAC,GAAG,KAAK,KAAA;AAC9F"}
@@ -14,6 +14,10 @@ export declare const storedPhaseInputSchema: z.ZodObject<{
14
14
  skill: z.ZodOptional<z.ZodString>;
15
15
  context: z.ZodOptional<z.ZodString>;
16
16
  instructions: z.ZodOptional<z.ZodString>;
17
+ goal: z.ZodOptional<z.ZodObject<{
18
+ objective: z.ZodString;
19
+ maxRuns: z.ZodOptional<z.ZodNumber>;
20
+ }, z.core.$strict>>;
17
21
  }, z.core.$strict>>>;
18
22
  nextPhases: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
19
23
  autoStart: z.ZodOptional<z.ZodBoolean>;
@@ -23,6 +27,10 @@ export declare const storedPhaseInputSchema: z.ZodObject<{
23
27
  autoApprove: z.ZodOptional<z.ZodBoolean>;
24
28
  autoApproveWhen: z.ZodOptional<z.ZodType<import("../index.js").RuleGroup, unknown, z.core.$ZodTypeInternals<import("../index.js").RuleGroup, unknown>>>;
25
29
  }, z.core.$strict>>>;
30
+ tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
31
+ factory_record_review_verdict: "factory_record_review_verdict";
32
+ factory_review_source: "factory_review_source";
33
+ }>>>>;
26
34
  }, z.core.$strict>;
27
35
  /**
28
36
  * A board's editable fields without its key, the shape of a replace. Only the shape: the board
@@ -44,6 +52,10 @@ export declare const storedBoardDefinitionSchema: z.ZodObject<{
44
52
  skill: z.ZodOptional<z.ZodString>;
45
53
  context: z.ZodOptional<z.ZodString>;
46
54
  instructions: z.ZodOptional<z.ZodString>;
55
+ goal: z.ZodOptional<z.ZodObject<{
56
+ objective: z.ZodString;
57
+ maxRuns: z.ZodOptional<z.ZodNumber>;
58
+ }, z.core.$strict>>;
47
59
  }, z.core.$strict>>>;
48
60
  nextPhases: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
49
61
  autoStart: z.ZodOptional<z.ZodBoolean>;
@@ -53,6 +65,10 @@ export declare const storedBoardDefinitionSchema: z.ZodObject<{
53
65
  autoApprove: z.ZodOptional<z.ZodBoolean>;
54
66
  autoApproveWhen: z.ZodOptional<z.ZodType<import("../index.js").RuleGroup, unknown, z.core.$ZodTypeInternals<import("../index.js").RuleGroup, unknown>>>;
55
67
  }, z.core.$strict>>>;
68
+ tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
69
+ factory_record_review_verdict: "factory_record_review_verdict";
70
+ factory_review_source: "factory_review_source";
71
+ }>>>>;
56
72
  }, z.core.$strict>>;
57
73
  }, z.core.$strict>;
58
74
  /**
@@ -76,6 +92,10 @@ export declare const storedBoardInputSchema: z.ZodObject<{
76
92
  skill: z.ZodOptional<z.ZodString>;
77
93
  context: z.ZodOptional<z.ZodString>;
78
94
  instructions: z.ZodOptional<z.ZodString>;
95
+ goal: z.ZodOptional<z.ZodObject<{
96
+ objective: z.ZodString;
97
+ maxRuns: z.ZodOptional<z.ZodNumber>;
98
+ }, z.core.$strict>>;
79
99
  }, z.core.$strict>>>;
80
100
  nextPhases: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
81
101
  autoStart: z.ZodOptional<z.ZodBoolean>;
@@ -85,6 +105,10 @@ export declare const storedBoardInputSchema: z.ZodObject<{
85
105
  autoApprove: z.ZodOptional<z.ZodBoolean>;
86
106
  autoApproveWhen: z.ZodOptional<z.ZodType<import("../index.js").RuleGroup, unknown, z.core.$ZodTypeInternals<import("../index.js").RuleGroup, unknown>>>;
87
107
  }, z.core.$strict>>>;
108
+ tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
109
+ factory_record_review_verdict: "factory_record_review_verdict";
110
+ factory_review_source: "factory_review_source";
111
+ }>>>>;
88
112
  }, z.core.$strict>>;
89
113
  key: z.ZodString;
90
114
  }, z.core.$strict>;
@@ -92,11 +116,10 @@ export declare const storedBoardInputSchema: z.ZodObject<{
92
116
  * Compiles a stored board through the same validator as `defineBoard()`. Its first phase is where
93
117
  * cards start.
94
118
  *
95
- * With `code`, the board is a project's edit of that code board: its fields come from the stored
96
- * definition and its behaviour from the code declaration, by phase key (`onEnter`, `onExit`,
97
- * `outcomes`) and for the board (`tools`, `events`, `sourceClosed`, `transitionPolicy`). The board
98
- * is rebuilt from the declaration, so the stored runner reaches the declared handlers. An edit code
99
- * behaviour can't honour ({@link codeBehaviourConflicts}) is refused.
119
+ * With `code`, the board is a project's edit of that code board: its phases come from the stored
120
+ * definition and the board-level behaviour from the code declaration (`tools`, `events`,
121
+ * `sourceClosed`, `transitionPolicy`). An edit that behaviour can't honour
122
+ * ({@link codeBehaviourConflicts}) is refused.
100
123
  */
101
124
  export declare function compileStoredBoard(board: StoredBoardInput, code?: InstalledBoard): InstalledBoard;
102
125
  /** A board served from a stored row, and what of its code board's behaviour it runs without. */
@@ -111,10 +134,6 @@ interface MergedStoredBoard {
111
134
  * edit from before a release added a phase or a code move, a row older than editable code boards)
112
135
  * still runs as stored.
113
136
  *
114
- * - A phase's `onEnter`, `onExit` and `outcomes` attach only when the row keeps the phase in the
115
- * shape they depend on: the same kind and, on phases with code handlers, the same runner context
116
- * and skill, the declared exit tool and no other. Outcomes whose target the row lacks or doesn't
117
- * allow are dropped.
118
137
  * - The board's `tools` always attach: they hold the exit-tool approval that keeps anyone but a
119
138
  * person from moving a card past an unapproved exit tool. If the row lacks a code phase, the
120
139
  * moves they make to it are refused, and that is reported.
@@ -130,10 +149,6 @@ interface MergedStoredBoard {
130
149
  export declare function mergeCodeBehaviour(row: StoredBoardInput, code: InstalledBoard): MergedStoredBoard;
131
150
  /** What a code board's behaviour holds fixed on each of its phases; the rest of the phase is editable. */
132
151
  interface CodePhaseBehaviour {
133
- /** Code handlers run on entering or leaving it, so its runner context and skill are fixed. */
134
- handlers: boolean;
135
- /** The exit tool its code behaviour waits for, if any. */
136
- exitToolId: string | null;
137
152
  /** Phases code moves cards to from it; they stay in its nextPhases. */
138
153
  requiredNextPhases: string[];
139
154
  }
@@ -141,11 +156,10 @@ interface CodePhaseBehaviour {
141
156
  export declare function codeBehaviourOf(code: InstalledBoard): Record<string, CodePhaseBehaviour>;
142
157
  /**
143
158
  * Why a stored definition of a code board's key can't run with that board's code behaviour, one
144
- * reason per locked change; empty when it can. Code handlers and checks name the board's phases,
145
- * its first phase, the context, skill and exit tool of phases with handlers, and the moves code
146
- * makes between phases (tool and event rules, `sourceClosed`, integrations, handler prompts), so
147
- * those stay as code declares them. Names, descriptions, added moves, start and approval
148
- * conditions, runner instructions and new phases are free.
159
+ * reason per locked change; empty when it can. Code (tool and event rules, `sourceClosed`,
160
+ * integrations) names the board's phases, its first phase, each phase's kind and the moves it
161
+ * makes between phases, so those stay as code declares them. Names, descriptions, runners, exit
162
+ * tools, phase tools, added moves, start and approval conditions and new phases are free.
149
163
  */
150
164
  export declare function codeBehaviourConflicts(board: StoredBoardInput, code: InstalledBoard): string[];
151
165
  /** Whether two storable definitions describe the same board once unset fields and defaults are resolved. */
@@ -1 +1 @@
1
- {"version":3,"file":"stored-board.d.ts","sourceRoot":"","sources":["../../src/boards/stored-board.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,mCAAmC,CAAC;AAG5F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAkBpD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;kBAYxB,CAAC;AAUZ;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAyC,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;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from "../rules/rule-group.js";
2
- import { BoardDefinitionError, compileBoardDefinition, declarationOf } from "./define-board.js";
2
+ import { BoardDefinitionError, FACTORY_PHASE_TOOLS, compileBoardDefinition, declarationOf } from "./define-board.js";
3
3
  import { z } from "zod";
4
4
  // src/boards/stored-board.ts
5
5
  const storedRunnerSchema = z.object({
6
6
  skill: z.string().optional(),
7
7
  context: z.string().optional(),
8
- instructions: z.string().optional()
8
+ instructions: z.string().optional(),
9
+ goal: z.object({
10
+ objective: z.string(),
11
+ maxRuns: z.number().optional()
12
+ }).strict().optional()
9
13
  }).strict();
10
14
  const storedExitToolSchema = z.object({
11
15
  id: z.string(),
@@ -25,7 +29,8 @@ const storedPhaseInputSchema = z.object({
25
29
  nextPhases: z.array(z.string()).nullish(),
26
30
  autoStart: z.boolean().optional(),
27
31
  autoStartWhen: cardRuleGroupSchema.nullish(),
28
- exitTool: storedExitToolSchema.nullish()
32
+ exitTool: storedExitToolSchema.nullish(),
33
+ tools: z.array(z.enum(FACTORY_PHASE_TOOLS)).nullish()
29
34
  }).strict();
30
35
  function storedBoardFields() {
31
36
  return {
@@ -68,28 +73,17 @@ function storedNextPhases(phase, phases) {
68
73
  * Compiles a stored board through the same validator as `defineBoard()`. Its first phase is where
69
74
  * cards start.
70
75
  *
71
- * With `code`, the board is a project's edit of that code board: its fields come from the stored
72
- * definition and its behaviour from the code declaration, by phase key (`onEnter`, `onExit`,
73
- * `outcomes`) and for the board (`tools`, `events`, `sourceClosed`, `transitionPolicy`). The board
74
- * is rebuilt from the declaration, so the stored runner reaches the declared handlers. An edit code
75
- * behaviour can't honour ({@link codeBehaviourConflicts}) is refused.
76
+ * With `code`, the board is a project's edit of that code board: its phases come from the stored
77
+ * definition and the board-level behaviour from the code declaration (`tools`, `events`,
78
+ * `sourceClosed`, `transitionPolicy`). An edit that behaviour can't honour
79
+ * ({@link codeBehaviourConflicts}) is refused.
76
80
  */
77
81
  function compileStoredBoard(board, code) {
78
82
  if (!code) return compileBoardDefinition(storedBoardConfig(board));
79
83
  const conflicts = codeBehaviourConflicts(board, code);
80
84
  if (conflicts.length > 0) throw new BoardDefinitionError(conflicts.join(" "));
81
85
  const declaration = codeDeclaration(code);
82
- const phases = {};
83
- for (const key of Object.keys(declaration.phases)) {
84
- const { outcomes, onEnter, onExit } = declaration.phases[key];
85
- phases[key] = {
86
- outcomes,
87
- onEnter,
88
- onExit
89
- };
90
- }
91
86
  return compileBoardDefinition(storedBoardConfig(board, {
92
- phases,
93
87
  tools: declaration.tools,
94
88
  events: declaration.events,
95
89
  transitionPolicy: declaration.transitionPolicy,
@@ -102,10 +96,6 @@ function compileStoredBoard(board, code) {
102
96
  * edit from before a release added a phase or a code move, a row older than editable code boards)
103
97
  * still runs as stored.
104
98
  *
105
- * - A phase's `onEnter`, `onExit` and `outcomes` attach only when the row keeps the phase in the
106
- * shape they depend on: the same kind and, on phases with code handlers, the same runner context
107
- * and skill, the declared exit tool and no other. Outcomes whose target the row lacks or doesn't
108
- * allow are dropped.
109
99
  * - The board's `tools` always attach: they hold the exit-tool approval that keeps anyone but a
110
100
  * person from moving a card past an unapproved exit tool. If the row lacks a code phase, the
111
101
  * moves they make to it are refused, and that is reported.
@@ -122,38 +112,13 @@ function mergeCodeBehaviour(row, code) {
122
112
  const declaration = codeDeclaration(code);
123
113
  const stored = new Map(row.phases.map((phase) => [phase.key, phase]));
124
114
  const problems = [];
125
- const phases = {};
126
115
  for (const [key, phase] of Object.entries(code.phases)) {
127
- const declared = declaration.phases[key];
128
- const outcomes = Object.entries(declared?.outcomes ?? {});
129
116
  const edited = stored.get(key);
130
- const conflicts = edited ? phaseShapeConflicts(key, phase, declared, edited) : [];
131
- if (edited && edited.kind === phase.kind) {
132
- const allowed = storedNextPhases(edited, row.phases);
133
- const outcomeTargets = new Set(outcomes.map(([, target]) => target));
134
- for (const target of phase.nextPhases) if (stored.has(target) && !allowed.includes(target) && !outcomeTargets.has(target)) problems.push(`Board "${row.key}" doesn't let phase "${key}" move cards to "${target}", so Factory's code can't make that move.`);
135
- }
136
- if (!hasHandlers(declared) && outcomes.length === 0) continue;
137
- if (!edited) {
138
- problems.push(`Phase "${key}" isn't on stored board "${row.key}", so its code behaviour doesn't run.`);
139
- continue;
140
- }
141
- if (conflicts.length > 0) {
142
- problems.push(...conflicts.map((conflict) => `Phase "${key}" runs without its code behaviour: ${conflict}`));
143
- continue;
144
- }
117
+ if (!edited || edited.kind !== phase.kind) continue;
145
118
  const allowed = storedNextPhases(edited, row.phases);
146
- const kept = {};
147
- for (const [outcome, target] of outcomes) if (!stored.has(target)) problems.push(`Phase "${key}" runs without its code outcome "${outcome}": phase "${target}" isn't stored.`);
148
- else if (!allowed.includes(target)) problems.push(`Phase "${key}" runs without its code outcome "${outcome}": the board doesn't let it move cards to "${target}".`);
149
- else kept[outcome] = target;
150
- phases[key] = {
151
- onEnter: declared?.onEnter,
152
- onExit: declared?.onExit,
153
- outcomes: Object.keys(kept).length > 0 ? kept : void 0
154
- };
119
+ for (const target of phase.nextPhases) if (stored.has(target) && !allowed.includes(target)) problems.push(`Board "${row.key}" doesn't let phase "${key}" move cards to "${target}", so Factory's code can't make that move.`);
155
120
  }
156
- const board = { phases };
121
+ const board = {};
157
122
  const missing = Object.keys(code.phases).filter((key) => !stored.has(key));
158
123
  const unfit = missing.length > 0 ? missingPhases(missing) : void 0;
159
124
  const tools = Object.keys(declaration.tools ?? {});
@@ -198,10 +163,7 @@ function missingPhases(keys) {
198
163
  function codeDeclaration(code) {
199
164
  return declarationOf(code) ?? code;
200
165
  }
201
- /**
202
- * The board config a stored definition declares, with the given code behaviour. The board is
203
- * rebuilt from the declaration's handlers, so the stored runner reaches them.
204
- */
166
+ /** The board config a stored definition declares, with the given code behaviour. */
205
167
  function storedBoardConfig(board, behaviour) {
206
168
  const [initial] = board.phases;
207
169
  if (!initial) throw new BoardDefinitionError("A board must define at least one phase.");
@@ -210,7 +172,6 @@ function storedBoardConfig(board, behaviour) {
210
172
  if (Object.hasOwn(phases, phase.key)) throw new BoardDefinitionError(`Board "${board.key}" declares phase "${phase.key}" more than once.`);
211
173
  const runner = phase.runner ? withoutUndefined(phase.runner) : void 0;
212
174
  const exitTool = phase.exitTool ? withoutUndefined(phase.exitTool) : void 0;
213
- const declared = behaviour && Object.hasOwn(behaviour.phases, phase.key) ? behaviour.phases[phase.key] : void 0;
214
175
  phases[phase.key] = withoutUndefined({
215
176
  name: phase.name,
216
177
  description: phase.description ?? void 0,
@@ -220,9 +181,7 @@ function storedBoardConfig(board, behaviour) {
220
181
  autoStart: phase.autoStart ? true : void 0,
221
182
  autoStartWhen: phase.autoStartWhen ?? void 0,
222
183
  exitTool,
223
- outcomes: declared?.outcomes,
224
- onEnter: declared?.onEnter,
225
- onExit: declared?.onExit
184
+ tools: phase.tools?.length ? phase.tools : void 0
226
185
  });
227
186
  }
228
187
  return {
@@ -239,26 +198,16 @@ function storedBoardConfig(board, behaviour) {
239
198
  }
240
199
  /** The per-phase locks `codeBehaviourConflicts` enforces, for clients that show them. */
241
200
  function codeBehaviourOf(code) {
242
- const declaration = declarationOf(code) ?? code;
243
- return Object.fromEntries(Object.entries(code.phases).map(([key, phase]) => [key, {
244
- handlers: phase.kind === "working" && hasHandlers(declaration.phases[key]),
245
- exitToolId: phase.kind === "working" ? phase.exitTool?.id ?? null : null,
246
- requiredNextPhases: [...phase.nextPhases]
247
- }]));
248
- }
249
- function hasHandlers(phase) {
250
- return Object.keys(phase?.onEnter ?? {}).length > 0 || Object.keys(phase?.onExit ?? {}).length > 0;
201
+ return Object.fromEntries(Object.entries(code.phases).map(([key, phase]) => [key, { requiredNextPhases: [...phase.nextPhases] }]));
251
202
  }
252
203
  /**
253
204
  * Why a stored definition of a code board's key can't run with that board's code behaviour, one
254
- * reason per locked change; empty when it can. Code handlers and checks name the board's phases,
255
- * its first phase, the context, skill and exit tool of phases with handlers, and the moves code
256
- * makes between phases (tool and event rules, `sourceClosed`, integrations, handler prompts), so
257
- * those stay as code declares them. Names, descriptions, added moves, start and approval
258
- * conditions, runner instructions and new phases are free.
205
+ * reason per locked change; empty when it can. Code (tool and event rules, `sourceClosed`,
206
+ * integrations) names the board's phases, its first phase, each phase's kind and the moves it
207
+ * makes between phases, so those stay as code declares them. Names, descriptions, runners, exit
208
+ * tools, phase tools, added moves, start and approval conditions and new phases are free.
259
209
  */
260
210
  function codeBehaviourConflicts(board, code) {
261
- const declaration = declarationOf(code) ?? code;
262
211
  const stored = new Map(board.phases.map((phase) => [phase.key, phase]));
263
212
  const conflicts = [];
264
213
  if (board.phases[0]?.key !== code.initialPhase) conflicts.push(`Cards on board "${code.id}" start in "${code.initialPhase}"; keep it the first phase.`);
@@ -269,35 +218,18 @@ function codeBehaviourConflicts(board, code) {
269
218
  conflicts.push(`${label} has code behaviour on board "${code.id}"; it can't be removed.`);
270
219
  continue;
271
220
  }
272
- conflicts.push(...phaseShapeConflicts(key, phase, declaration.phases[key], edited));
273
- if (edited.kind !== phase.kind) continue;
221
+ if (edited.kind !== phase.kind) {
222
+ conflicts.push(`${label} must stay ${phase.kind}; its code behaviour depends on it.`);
223
+ continue;
224
+ }
274
225
  const nextPhases = storedNextPhases(edited, board.phases);
275
- const outcomes = new Map(Object.entries(phase.outcomes ?? {}).map(([outcome, target]) => [target, outcome]));
276
226
  for (const target of phase.nextPhases) {
277
227
  if (nextPhases.includes(target)) continue;
278
- const outcome = outcomes.get(target);
279
- conflicts.push(outcome ? `${label} outcome "${outcome}" moves cards to "${target}"; keep it in nextPhases.` : `${label}: Factory's code moves cards from it to "${target}"; keep it in nextPhases.`);
228
+ conflicts.push(`${label}: Factory's code moves cards from it to "${target}"; keep it in nextPhases.`);
280
229
  }
281
230
  }
282
231
  return conflicts;
283
232
  }
284
- /**
285
- * Why a stored phase isn't in the shape its code behaviour depends on: its kind and, on a working
286
- * phase, the runner context and skill its code handlers run with and the exit tool they wait for.
287
- */
288
- function phaseShapeConflicts(key, phase, declared, edited) {
289
- const label = `Phase "${key}"`;
290
- if (edited.kind !== phase.kind) return [`${label} must stay ${phase.kind}; its code behaviour depends on it.`];
291
- if (phase.kind !== "working") return [];
292
- const conflicts = [];
293
- if (hasHandlers(declared)) {
294
- if ((edited.runner?.context ?? "work") !== phase.runner.context) conflicts.push(`${label} runs its code handlers in the "${phase.runner.context}" context; keep runner.context.`);
295
- if (edited.runner?.skill !== phase.runner.skill) conflicts.push(phase.runner.skill ? `${label} code handlers run with skill "${phase.runner.skill}"; keep runner.skill.` : `${label} code handlers choose the skill; leave runner.skill unset.`);
296
- }
297
- if (phase.exitTool && edited.exitTool?.id !== phase.exitTool.id) conflicts.push(`${label} code behaviour waits for exit tool "${phase.exitTool.id}"; keep exitTool.id.`);
298
- else if (!phase.exitTool && edited.exitTool && hasHandlers(declared)) conflicts.push(`${label} code handlers move cards on without an exit tool; leave exitTool unset.`);
299
- return conflicts;
300
- }
301
233
  /** Whether two storable definitions describe the same board once unset fields and defaults are resolved. */
302
234
  function sameBoardDefinition(a, b) {
303
235
  return canonicalJson(boardDefinitionOf(compileStoredBoard(a))) === canonicalJson(boardDefinitionOf(compileStoredBoard(b)));
@@ -331,7 +263,8 @@ function storedPhase(key, phase) {
331
263
  runner: withoutUndefined({
332
264
  skill: phase.runner.skill,
333
265
  context: phase.runner.context,
334
- instructions: phase.runner.instructions
266
+ instructions: phase.runner.instructions,
267
+ goal: phase.runner.goal ? { ...phase.runner.goal } : void 0
335
268
  }),
336
269
  autoStart: phase.autoStart ? true : void 0,
337
270
  autoStartWhen: phase.autoStartWhen,
@@ -339,7 +272,8 @@ function storedPhase(key, phase) {
339
272
  id: phase.exitTool.id,
340
273
  autoApprove: phase.exitTool.autoApprove,
341
274
  autoApproveWhen: phase.exitTool.autoApproveWhen
342
- }) : void 0
275
+ }) : void 0,
276
+ tools: phase.tools ? [...phase.tools] : void 0
343
277
  } : {}
344
278
  });
345
279
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stored-board.js","names":[],"sources":["../../src/boards/stored-board.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { cardRuleGroupSchema } from '../rules/rule-group.js';\nimport type { StoredBoardInput, StoredPhaseInput } from '../storage/domains/boards/base.js';\nimport { BoardDefinitionError, compileBoardDefinition, declarationOf, DEFAULT_PHASE_CONTEXT } from './define-board.js';\nimport type { AnyBoardConfig, BoardPhase, BoardPhaseDefinition } from './define-board.js';\nimport type { InstalledBoard } from './registry.js';\n\nconst storedRunnerSchema = z\n .object({\n skill: z.string().optional(),\n context: z.string().optional(),\n instructions: z.string().optional(),\n })\n .strict();\n\nconst storedExitToolSchema = z\n .object({\n id: z.string(),\n autoApprove: z.boolean().optional(),\n autoApproveWhen: cardRuleGroupSchema.optional(),\n })\n .strict();\n\nexport const storedPhaseInputSchema = z\n .object({\n key: z.string(),\n name: z.string(),\n description: z.string().nullish(),\n kind: z.enum(['resting', 'working', 'terminal']),\n runner: storedRunnerSchema.nullish(),\n nextPhases: z.array(z.string()).nullish(),\n autoStart: z.boolean().optional(),\n autoStartWhen: cardRuleGroupSchema.nullish(),\n exitTool: storedExitToolSchema.nullish(),\n })\n .strict();\n\nfunction storedBoardFields() {\n return {\n name: z.string(),\n description: z.string().nullish(),\n phases: z.array(storedPhaseInputSchema).min(1, 'A board must define at least one phase.'),\n };\n}\n\n/**\n * A board's editable fields without its key, the shape of a replace. Only the shape: the board\n * rules run once the key is known, through {@link storedBoardInputSchema}.\n */\nexport const storedBoardDefinitionSchema = z.object(storedBoardFields()).strict();\n\n/**\n * A board as the API accepts it. Beyond the shape, it holds every rule `defineBoard()` enforces\n * (identifiers, lengths, phase kinds, runners, exit tools, conditions, targets), reported with\n * the same messages.\n */\nexport const storedBoardInputSchema = z\n .object({ key: z.string(), ...storedBoardFields() })\n .strict()\n .superRefine((input, context) => {\n try {\n compileStoredBoard(input);\n } catch (error) {\n if (!(error instanceof BoardDefinitionError)) throw error;\n context.addIssue({ code: 'custom', message: error.message });\n }\n });\n\n/** Phases a stored phase may move to: unset on a resting or working phase means every other phase. */\nfunction storedNextPhases(phase: StoredPhaseInput, phases: readonly StoredPhaseInput[]): string[] {\n if (phase.nextPhases != null) return phase.nextPhases;\n if (phase.kind === 'terminal') return [];\n return phases.filter(other => other.key !== phase.key).map(other => other.key);\n}\n\n/**\n * Compiles a stored board through the same validator as `defineBoard()`. Its first phase is where\n * cards start.\n *\n * With `code`, the board is a project's edit of that code board: its fields come from the stored\n * definition and its behaviour from the code declaration, by phase key (`onEnter`, `onExit`,\n * `outcomes`) and for the board (`tools`, `events`, `sourceClosed`, `transitionPolicy`). The board\n * is rebuilt from the declaration, so the stored runner reaches the declared handlers. An edit code\n * behaviour can't honour ({@link codeBehaviourConflicts}) is refused.\n */\nexport function compileStoredBoard(board: StoredBoardInput, code?: InstalledBoard): InstalledBoard {\n if (!code) return compileBoardDefinition(storedBoardConfig(board));\n const conflicts = codeBehaviourConflicts(board, code);\n if (conflicts.length > 0) throw new BoardDefinitionError(conflicts.join(' '));\n const declaration = codeDeclaration(code);\n const phases: Record<string, PhaseBehaviour> = {};\n for (const key of Object.keys(declaration.phases)) {\n const { outcomes, onEnter, onExit } = declaration.phases[key]!;\n phases[key] = { outcomes, onEnter, onExit };\n }\n return compileBoardDefinition(\n storedBoardConfig(board, {\n phases,\n tools: declaration.tools,\n events: declaration.events,\n transitionPolicy: declaration.transitionPolicy,\n sourceClosed: declaration.sourceClosed,\n }),\n code,\n );\n}\n\n/** A board served from a stored row, and what of its code board's behaviour it runs without. */\ninterface MergedStoredBoard {\n board: InstalledBoard;\n /** One per piece of code behaviour the row can't run with; empty when it runs with all of it. */\n problems: string[];\n}\n\n/**\n * Serves a stored row of a code board's key with the code behaviour that still fits it. Unlike\n * {@link compileStoredBoard}, nothing is refused: a row that fell out of step with its code (an\n * edit from before a release added a phase or a code move, a row older than editable code boards)\n * still runs as stored.\n *\n * - A phase's `onEnter`, `onExit` and `outcomes` attach only when the row keeps the phase in the\n * shape they depend on: the same kind and, on phases with code handlers, the same runner context\n * and skill, the declared exit tool and no other. Outcomes whose target the row lacks or doesn't\n * allow are dropped.\n * - The board's `tools` always attach: they hold the exit-tool approval that keeps anyone but a\n * person from moving a card past an unapproved exit tool. If the row lacks a code phase, the\n * moves they make to it are refused, and that is reported.\n * - The board's `events` and `transitionPolicy` attach only when the row has every code phase,\n * since their handlers may move cards to any of them; `sourceClosed` when both of its phases are\n * stored and terminal.\n * - A move code makes that the row's `nextPhases` don't allow is reported; code making it is refused.\n * - If the board still fails to compile with that behaviour, it runs without any.\n *\n * The result links to `code` as its code board either way. Throws only when the row itself is\n * invalid.\n */\nexport function mergeCodeBehaviour(row: StoredBoardInput, code: InstalledBoard): MergedStoredBoard {\n const declaration = codeDeclaration(code);\n const stored = new Map(row.phases.map(phase => [phase.key, phase]));\n const problems: string[] = [];\n const phases: Record<string, PhaseBehaviour> = {};\n for (const [key, phase] of Object.entries(code.phases) as [string, BoardPhase<string>][]) {\n const declared = declaration.phases[key];\n const outcomes = Object.entries(declared?.outcomes ?? {});\n const edited = stored.get(key);\n const conflicts = edited ? phaseShapeConflicts(key, phase, declared, edited) : [];\n if (edited && edited.kind === phase.kind) {\n // A move code makes that the row doesn't allow is refused when code makes it.\n const allowed = storedNextPhases(edited, row.phases);\n const outcomeTargets = new Set(outcomes.map(([, target]) => target));\n for (const target of phase.nextPhases) {\n if (stored.has(target) && !allowed.includes(target) && !outcomeTargets.has(target)) {\n problems.push(\n `Board \"${row.key}\" doesn't let phase \"${key}\" move cards to \"${target}\", so Factory's code can't make that move.`,\n );\n }\n }\n }\n if (!hasHandlers(declared) && outcomes.length === 0) continue;\n if (!edited) {\n problems.push(`Phase \"${key}\" isn't on stored board \"${row.key}\", so its code behaviour doesn't run.`);\n continue;\n }\n if (conflicts.length > 0) {\n problems.push(...conflicts.map(conflict => `Phase \"${key}\" runs without its code behaviour: ${conflict}`));\n continue;\n }\n const allowed = storedNextPhases(edited, row.phases);\n const kept: Record<string, string> = {};\n for (const [outcome, target] of outcomes) {\n if (!stored.has(target)) {\n problems.push(`Phase \"${key}\" runs without its code outcome \"${outcome}\": phase \"${target}\" isn't stored.`);\n } else if (!allowed.includes(target)) {\n problems.push(\n `Phase \"${key}\" runs without its code outcome \"${outcome}\": the board doesn't let it move cards to \"${target}\".`,\n );\n } else kept[outcome] = target;\n }\n phases[key] = {\n onEnter: declared?.onEnter,\n onExit: declared?.onExit,\n outcomes: Object.keys(kept).length > 0 ? kept : undefined,\n };\n }\n\n const board: BoardBehaviour = { phases };\n const missing = Object.keys(code.phases).filter(key => !stored.has(key));\n const unfit = missing.length > 0 ? missingPhases(missing) : undefined;\n const tools = Object.keys(declaration.tools ?? {});\n if (tools.length > 0) {\n board.tools = declaration.tools;\n if (unfit) {\n problems.push(\n `Board \"${row.key}\" keeps its code tool rules (${tools.join(', ')}), but can't move cards where they lead: ${unfit}`,\n );\n }\n }\n const events = Object.keys(declaration.events ?? {});\n if (events.length > 0) {\n if (unfit) problems.push(`Board \"${row.key}\" runs without its code event rules (${events.join(', ')}): ${unfit}`);\n else board.events = declaration.events;\n }\n if (declaration.transitionPolicy) {\n if (unfit) problems.push(`Board \"${row.key}\" runs without its code transition policy: ${unfit}`);\n else board.transitionPolicy = declaration.transitionPolicy;\n }\n const sourceClosed = declaration.sourceClosed;\n if (sourceClosed) {\n const closed = [sourceClosed.completed, sourceClosed.canceled];\n const closedMissing = closed.filter(key => !stored.has(key));\n const closedOpen = closed.filter(key => stored.has(key) && stored.get(key)!.kind !== 'terminal');\n if (closedMissing.length > 0) {\n problems.push(`Board \"${row.key}\" doesn't move cards when their source closes: ${missingPhases(closedMissing)}`);\n } else if (closedOpen.length > 0) {\n problems.push(\n `Board \"${row.key}\" doesn't move cards when their source closes: ${\n closedOpen.length === 1\n ? `phase \"${closedOpen[0]}\" isn't terminal.`\n : `phases ${closedOpen.map(key => `\"${key}\"`).join(', ')} aren't terminal.`\n }`,\n );\n } else board.sourceClosed = sourceClosed;\n }\n\n try {\n return { board: compileBoardDefinition(storedBoardConfig(row, board), code), problems };\n } catch (error) {\n if (!(error instanceof BoardDefinitionError)) throw error;\n return {\n board: compileBoardDefinition(storedBoardConfig(row), code),\n problems: [...problems, `Board \"${row.key}\" runs without its code behaviour: ${error.message}`],\n };\n }\n}\n\nfunction missingPhases(keys: string[]): string {\n return keys.length === 1\n ? `phase \"${keys[0]}\" isn't stored.`\n : `phases ${keys.map(key => `\"${key}\"`).join(', ')} aren't stored.`;\n}\n\n/** The code behaviour one stored phase runs with. */\ninterface PhaseBehaviour {\n outcomes?: Readonly<Record<string, string>>;\n onEnter?: BoardPhaseDefinition<string>['onEnter'];\n onExit?: BoardPhaseDefinition<string>['onExit'];\n}\n\n/** The code behaviour a stored board runs with, by phase key and for the board. */\ninterface BoardBehaviour {\n phases: Record<string, PhaseBehaviour>;\n tools?: AnyBoardConfig['tools'];\n events?: AnyBoardConfig['events'];\n transitionPolicy?: AnyBoardConfig['transitionPolicy'];\n sourceClosed?: AnyBoardConfig['sourceClosed'];\n}\n\nfunction codeDeclaration(code: InstalledBoard): AnyBoardConfig {\n return declarationOf(code) ?? code;\n}\n\n/**\n * The board config a stored definition declares, with the given code behaviour. The board is\n * rebuilt from the declaration's handlers, so the stored runner reaches them.\n */\nfunction storedBoardConfig(board: StoredBoardInput, behaviour?: BoardBehaviour): AnyBoardConfig {\n const [initial] = board.phases;\n if (!initial) throw new BoardDefinitionError('A board must define at least one phase.');\n const phases: Record<string, BoardPhaseDefinition<string>> = {};\n for (const phase of board.phases) {\n if (Object.hasOwn(phases, phase.key)) {\n throw new BoardDefinitionError(`Board \"${board.key}\" declares phase \"${phase.key}\" more than once.`);\n }\n const runner = phase.runner ? withoutUndefined(phase.runner) : undefined;\n const exitTool = phase.exitTool ? withoutUndefined(phase.exitTool) : undefined;\n const declared = behaviour && Object.hasOwn(behaviour.phases, phase.key) ? behaviour.phases[phase.key] : undefined;\n phases[phase.key] = withoutUndefined({\n name: phase.name,\n description: phase.description ?? undefined,\n kind: phase.kind,\n nextPhases: storedNextPhases(phase, board.phases),\n runner,\n autoStart: phase.autoStart ? true : undefined,\n autoStartWhen: phase.autoStartWhen ?? undefined,\n exitTool,\n outcomes: declared?.outcomes,\n onEnter: declared?.onEnter,\n onExit: declared?.onExit,\n }) as BoardPhaseDefinition<string>;\n }\n return {\n id: board.key,\n name: board.name,\n ...(board.description != null ? { description: board.description } : {}),\n initialPhase: initial.key,\n phases,\n ...(behaviour?.tools ? { tools: behaviour.tools } : {}),\n ...(behaviour?.events ? { events: behaviour.events } : {}),\n ...(behaviour?.transitionPolicy ? { transitionPolicy: behaviour.transitionPolicy } : {}),\n ...(behaviour?.sourceClosed ? { sourceClosed: behaviour.sourceClosed } : {}),\n };\n}\n\n/** What a code board's behaviour holds fixed on each of its phases; the rest of the phase is editable. */\ninterface CodePhaseBehaviour {\n /** Code handlers run on entering or leaving it, so its runner context and skill are fixed. */\n handlers: boolean;\n /** The exit tool its code behaviour waits for, if any. */\n exitToolId: string | null;\n /** Phases code moves cards to from it; they stay in its nextPhases. */\n requiredNextPhases: string[];\n}\n\n/** The per-phase locks `codeBehaviourConflicts` enforces, for clients that show them. */\nexport function codeBehaviourOf(code: InstalledBoard): Record<string, CodePhaseBehaviour> {\n const declaration: AnyBoardConfig = declarationOf(code) ?? code;\n return Object.fromEntries(\n (Object.entries(code.phases) as [string, BoardPhase<string>][]).map(([key, phase]) => [\n key,\n {\n handlers: phase.kind === 'working' && hasHandlers(declaration.phases[key]),\n exitToolId: phase.kind === 'working' ? (phase.exitTool?.id ?? null) : null,\n requiredNextPhases: [...phase.nextPhases],\n },\n ]),\n );\n}\n\nfunction hasHandlers(phase: BoardPhaseDefinition<string> | undefined): boolean {\n return Object.keys(phase?.onEnter ?? {}).length > 0 || Object.keys(phase?.onExit ?? {}).length > 0;\n}\n\n/**\n * Why a stored definition of a code board's key can't run with that board's code behaviour, one\n * reason per locked change; empty when it can. Code handlers and checks name the board's phases,\n * its first phase, the context, skill and exit tool of phases with handlers, and the moves code\n * makes between phases (tool and event rules, `sourceClosed`, integrations, handler prompts), so\n * those stay as code declares them. Names, descriptions, added moves, start and approval\n * conditions, runner instructions and new phases are free.\n */\nexport function codeBehaviourConflicts(board: StoredBoardInput, code: InstalledBoard): string[] {\n const declaration: AnyBoardConfig = declarationOf(code) ?? code;\n const stored = new Map(board.phases.map(phase => [phase.key, phase]));\n const conflicts: string[] = [];\n if (board.phases[0]?.key !== code.initialPhase) {\n conflicts.push(`Cards on board \"${code.id}\" start in \"${code.initialPhase}\"; keep it the first phase.`);\n }\n for (const [key, phase] of Object.entries(code.phases) as [string, BoardPhase<string>][]) {\n const edited = stored.get(key);\n const label = `Phase \"${key}\"`;\n if (!edited) {\n conflicts.push(`${label} has code behaviour on board \"${code.id}\"; it can't be removed.`);\n continue;\n }\n conflicts.push(...phaseShapeConflicts(key, phase, declaration.phases[key], edited));\n if (edited.kind !== phase.kind) continue;\n const nextPhases = storedNextPhases(edited, board.phases);\n const outcomes = new Map(Object.entries(phase.outcomes ?? {}).map(([outcome, target]) => [target, outcome]));\n for (const target of phase.nextPhases) {\n if (nextPhases.includes(target)) continue;\n const outcome = outcomes.get(target);\n conflicts.push(\n outcome\n ? `${label} outcome \"${outcome}\" moves cards to \"${target}\"; keep it in nextPhases.`\n : `${label}: Factory's code moves cards from it to \"${target}\"; keep it in nextPhases.`,\n );\n }\n }\n return conflicts;\n}\n\n/**\n * Why a stored phase isn't in the shape its code behaviour depends on: its kind and, on a working\n * phase, the runner context and skill its code handlers run with and the exit tool they wait for.\n */\nfunction phaseShapeConflicts(\n key: string,\n phase: BoardPhase<string>,\n declared: BoardPhaseDefinition<string> | undefined,\n edited: StoredPhaseInput,\n): string[] {\n const label = `Phase \"${key}\"`;\n if (edited.kind !== phase.kind) return [`${label} must stay ${phase.kind}; its code behaviour depends on it.`];\n if (phase.kind !== 'working') return [];\n const conflicts: string[] = [];\n if (hasHandlers(declared)) {\n const context = edited.runner?.context ?? DEFAULT_PHASE_CONTEXT;\n if (context !== phase.runner.context) {\n conflicts.push(`${label} runs its code handlers in the \"${phase.runner.context}\" context; keep runner.context.`);\n }\n if (edited.runner?.skill !== phase.runner.skill) {\n conflicts.push(\n phase.runner.skill\n ? `${label} code handlers run with skill \"${phase.runner.skill}\"; keep runner.skill.`\n : `${label} code handlers choose the skill; leave runner.skill unset.`,\n );\n }\n }\n if (phase.exitTool && edited.exitTool?.id !== phase.exitTool.id) {\n conflicts.push(`${label} code behaviour waits for exit tool \"${phase.exitTool.id}\"; keep exitTool.id.`);\n } else if (!phase.exitTool && edited.exitTool && hasHandlers(declared)) {\n // An exit tool gates every move out of the phase, including the ones its code handlers make.\n conflicts.push(`${label} code handlers move cards on without an exit tool; leave exitTool unset.`);\n }\n return conflicts;\n}\n\n/** Whether two storable definitions describe the same board once unset fields and defaults are resolved. */\nexport function sameBoardDefinition(a: StoredBoardInput, b: StoredBoardInput): boolean {\n return (\n canonicalJson(boardDefinitionOf(compileStoredBoard(a))) === canonicalJson(boardDefinitionOf(compileStoredBoard(b)))\n );\n}\n\nfunction canonicalJson(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n const entries = Object.entries(value)\n .filter(([, entry]) => entry !== undefined)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n return `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(',')}}`;\n }\n return JSON.stringify(value);\n}\n\n/**\n * A board's storable definition, in the shape the boards API reads and writes. The initial phase\n * comes first and every phase's resolved `nextPhases` is written out.\n */\nexport function boardDefinitionOf(board: InstalledBoard): StoredBoardInput {\n const order = [board.initialPhase, ...Object.keys(board.phases).filter(key => key !== board.initialPhase)];\n return {\n key: board.id,\n name: board.name,\n ...(board.description !== undefined ? { description: board.description } : {}),\n phases: order.map(key => storedPhase(key, board.phases[key]!)),\n };\n}\n\nfunction storedPhase(key: string, phase: BoardPhase<string>): StoredPhaseInput {\n return withoutUndefined({\n key,\n name: phase.name,\n description: phase.description,\n kind: phase.kind,\n nextPhases: [...phase.nextPhases],\n ...(phase.kind === 'working'\n ? {\n runner: withoutUndefined({\n skill: phase.runner.skill,\n context: phase.runner.context,\n instructions: phase.runner.instructions,\n }),\n autoStart: phase.autoStart ? true : undefined,\n autoStartWhen: phase.autoStartWhen,\n exitTool: phase.exitTool\n ? withoutUndefined({\n id: phase.exitTool.id,\n autoApprove: phase.exitTool.autoApprove,\n autoApproveWhen: phase.exitTool.autoApproveWhen,\n })\n : undefined,\n }\n : {}),\n });\n}\n\nfunction withoutUndefined<T extends object>(value: T): T {\n return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)) as T;\n}\n"],"mappings":";;;;AAQA,MAAM,qBAAqB,EACxB,OAAO;CACN,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,cAAc,EAAE,OAAO,CAAC,CAAC,SAAS;AACpC,CAAC,CAAC,CACD,OAAO;AAEV,MAAM,uBAAuB,EAC1B,OAAO;CACN,IAAI,EAAE,OAAO;CACb,aAAa,EAAE,QAAQ,CAAC,CAAC,SAAS;CAClC,iBAAiB,oBAAoB,SAAS;AAChD,CAAC,CAAC,CACD,OAAO;AAEV,MAAa,yBAAyB,EACnC,OAAO;CACN,KAAK,EAAE,OAAO;CACd,MAAM,EAAE,OAAO;CACf,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ;CAChC,MAAM,EAAE,KAAK;EAAC;EAAW;EAAW;CAAU,CAAC;CAC/C,QAAQ,mBAAmB,QAAQ;CACnC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ;CACxC,WAAW,EAAE,QAAQ,CAAC,CAAC,SAAS;CAChC,eAAe,oBAAoB,QAAQ;CAC3C,UAAU,qBAAqB,QAAQ;AACzC,CAAC,CAAC,CACD,OAAO;AAEV,SAAS,oBAAoB;CAC3B,OAAO;EACL,MAAM,EAAE,OAAO;EACf,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ;EAChC,QAA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stored-board.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { cardRuleGroupSchema } from '../rules/rule-group.js';\nimport type { StoredBoardInput, StoredPhaseInput } from '../storage/domains/boards/base.js';\nimport { BoardDefinitionError, compileBoardDefinition, declarationOf, FACTORY_PHASE_TOOLS } from './define-board.js';\nimport type { AnyBoardConfig, BoardPhase, BoardPhaseDefinition } from './define-board.js';\nimport type { InstalledBoard } from './registry.js';\n\nconst storedRunnerSchema = z\n .object({\n skill: z.string().optional(),\n context: z.string().optional(),\n instructions: z.string().optional(),\n goal: z.object({ objective: z.string(), maxRuns: z.number().optional() }).strict().optional(),\n })\n .strict();\n\nconst storedExitToolSchema = z\n .object({\n id: z.string(),\n autoApprove: z.boolean().optional(),\n autoApproveWhen: cardRuleGroupSchema.optional(),\n })\n .strict();\n\nexport const storedPhaseInputSchema = z\n .object({\n key: z.string(),\n name: z.string(),\n description: z.string().nullish(),\n kind: z.enum(['resting', 'working', 'terminal']),\n runner: storedRunnerSchema.nullish(),\n nextPhases: z.array(z.string()).nullish(),\n autoStart: z.boolean().optional(),\n autoStartWhen: cardRuleGroupSchema.nullish(),\n exitTool: storedExitToolSchema.nullish(),\n tools: z.array(z.enum(FACTORY_PHASE_TOOLS)).nullish(),\n })\n .strict();\n\nfunction storedBoardFields() {\n return {\n name: z.string(),\n description: z.string().nullish(),\n phases: z.array(storedPhaseInputSchema).min(1, 'A board must define at least one phase.'),\n };\n}\n\n/**\n * A board's editable fields without its key, the shape of a replace. Only the shape: the board\n * rules run once the key is known, through {@link storedBoardInputSchema}.\n */\nexport const storedBoardDefinitionSchema = z.object(storedBoardFields()).strict();\n\n/**\n * A board as the API accepts it. Beyond the shape, it holds every rule `defineBoard()` enforces\n * (identifiers, lengths, phase kinds, runners, exit tools, conditions, targets), reported with\n * the same messages.\n */\nexport const storedBoardInputSchema = z\n .object({ key: z.string(), ...storedBoardFields() })\n .strict()\n .superRefine((input, context) => {\n try {\n compileStoredBoard(input);\n } catch (error) {\n if (!(error instanceof BoardDefinitionError)) throw error;\n context.addIssue({ code: 'custom', message: error.message });\n }\n });\n\n/** Phases a stored phase may move to: unset on a resting or working phase means every other phase. */\nfunction storedNextPhases(phase: StoredPhaseInput, phases: readonly StoredPhaseInput[]): string[] {\n if (phase.nextPhases != null) return phase.nextPhases;\n if (phase.kind === 'terminal') return [];\n return phases.filter(other => other.key !== phase.key).map(other => other.key);\n}\n\n/**\n * Compiles a stored board through the same validator as `defineBoard()`. Its first phase is where\n * cards start.\n *\n * With `code`, the board is a project's edit of that code board: its phases come from the stored\n * definition and the board-level behaviour from the code declaration (`tools`, `events`,\n * `sourceClosed`, `transitionPolicy`). An edit that behaviour can't honour\n * ({@link codeBehaviourConflicts}) is refused.\n */\nexport function compileStoredBoard(board: StoredBoardInput, code?: InstalledBoard): InstalledBoard {\n if (!code) return compileBoardDefinition(storedBoardConfig(board));\n const conflicts = codeBehaviourConflicts(board, code);\n if (conflicts.length > 0) throw new BoardDefinitionError(conflicts.join(' '));\n const declaration = codeDeclaration(code);\n return compileBoardDefinition(\n storedBoardConfig(board, {\n tools: declaration.tools,\n events: declaration.events,\n transitionPolicy: declaration.transitionPolicy,\n sourceClosed: declaration.sourceClosed,\n }),\n code,\n );\n}\n\n/** A board served from a stored row, and what of its code board's behaviour it runs without. */\ninterface MergedStoredBoard {\n board: InstalledBoard;\n /** One per piece of code behaviour the row can't run with; empty when it runs with all of it. */\n problems: string[];\n}\n\n/**\n * Serves a stored row of a code board's key with the code behaviour that still fits it. Unlike\n * {@link compileStoredBoard}, nothing is refused: a row that fell out of step with its code (an\n * edit from before a release added a phase or a code move, a row older than editable code boards)\n * still runs as stored.\n *\n * - The board's `tools` always attach: they hold the exit-tool approval that keeps anyone but a\n * person from moving a card past an unapproved exit tool. If the row lacks a code phase, the\n * moves they make to it are refused, and that is reported.\n * - The board's `events` and `transitionPolicy` attach only when the row has every code phase,\n * since their handlers may move cards to any of them; `sourceClosed` when both of its phases are\n * stored and terminal.\n * - A move code makes that the row's `nextPhases` don't allow is reported; code making it is refused.\n * - If the board still fails to compile with that behaviour, it runs without any.\n *\n * The result links to `code` as its code board either way. Throws only when the row itself is\n * invalid.\n */\nexport function mergeCodeBehaviour(row: StoredBoardInput, code: InstalledBoard): MergedStoredBoard {\n const declaration = codeDeclaration(code);\n const stored = new Map(row.phases.map(phase => [phase.key, phase]));\n const problems: string[] = [];\n for (const [key, phase] of Object.entries(code.phases) as [string, BoardPhase<string>][]) {\n const edited = stored.get(key);\n if (!edited || edited.kind !== phase.kind) continue;\n // A move code makes that the row doesn't allow is refused when code makes it.\n const allowed = storedNextPhases(edited, row.phases);\n for (const target of phase.nextPhases) {\n if (stored.has(target) && !allowed.includes(target)) {\n problems.push(\n `Board \"${row.key}\" doesn't let phase \"${key}\" move cards to \"${target}\", so Factory's code can't make that move.`,\n );\n }\n }\n }\n\n const board: BoardBehaviour = {};\n const missing = Object.keys(code.phases).filter(key => !stored.has(key));\n const unfit = missing.length > 0 ? missingPhases(missing) : undefined;\n const tools = Object.keys(declaration.tools ?? {});\n if (tools.length > 0) {\n board.tools = declaration.tools;\n if (unfit) {\n problems.push(\n `Board \"${row.key}\" keeps its code tool rules (${tools.join(', ')}), but can't move cards where they lead: ${unfit}`,\n );\n }\n }\n const events = Object.keys(declaration.events ?? {});\n if (events.length > 0) {\n if (unfit) problems.push(`Board \"${row.key}\" runs without its code event rules (${events.join(', ')}): ${unfit}`);\n else board.events = declaration.events;\n }\n if (declaration.transitionPolicy) {\n if (unfit) problems.push(`Board \"${row.key}\" runs without its code transition policy: ${unfit}`);\n else board.transitionPolicy = declaration.transitionPolicy;\n }\n const sourceClosed = declaration.sourceClosed;\n if (sourceClosed) {\n const closed = [sourceClosed.completed, sourceClosed.canceled];\n const closedMissing = closed.filter(key => !stored.has(key));\n const closedOpen = closed.filter(key => stored.has(key) && stored.get(key)!.kind !== 'terminal');\n if (closedMissing.length > 0) {\n problems.push(`Board \"${row.key}\" doesn't move cards when their source closes: ${missingPhases(closedMissing)}`);\n } else if (closedOpen.length > 0) {\n problems.push(\n `Board \"${row.key}\" doesn't move cards when their source closes: ${\n closedOpen.length === 1\n ? `phase \"${closedOpen[0]}\" isn't terminal.`\n : `phases ${closedOpen.map(key => `\"${key}\"`).join(', ')} aren't terminal.`\n }`,\n );\n } else board.sourceClosed = sourceClosed;\n }\n\n try {\n return { board: compileBoardDefinition(storedBoardConfig(row, board), code), problems };\n } catch (error) {\n if (!(error instanceof BoardDefinitionError)) throw error;\n return {\n board: compileBoardDefinition(storedBoardConfig(row), code),\n problems: [...problems, `Board \"${row.key}\" runs without its code behaviour: ${error.message}`],\n };\n }\n}\n\nfunction missingPhases(keys: string[]): string {\n return keys.length === 1\n ? `phase \"${keys[0]}\" isn't stored.`\n : `phases ${keys.map(key => `\"${key}\"`).join(', ')} aren't stored.`;\n}\n\n/** The code behaviour a stored board runs with. */\ninterface BoardBehaviour {\n tools?: AnyBoardConfig['tools'];\n events?: AnyBoardConfig['events'];\n transitionPolicy?: AnyBoardConfig['transitionPolicy'];\n sourceClosed?: AnyBoardConfig['sourceClosed'];\n}\n\nfunction codeDeclaration(code: InstalledBoard): AnyBoardConfig {\n return declarationOf(code) ?? code;\n}\n\n/** The board config a stored definition declares, with the given code behaviour. */\nfunction storedBoardConfig(board: StoredBoardInput, behaviour?: BoardBehaviour): AnyBoardConfig {\n const [initial] = board.phases;\n if (!initial) throw new BoardDefinitionError('A board must define at least one phase.');\n const phases: Record<string, BoardPhaseDefinition<string>> = {};\n for (const phase of board.phases) {\n if (Object.hasOwn(phases, phase.key)) {\n throw new BoardDefinitionError(`Board \"${board.key}\" declares phase \"${phase.key}\" more than once.`);\n }\n const runner = phase.runner ? withoutUndefined(phase.runner) : undefined;\n const exitTool = phase.exitTool ? withoutUndefined(phase.exitTool) : undefined;\n phases[phase.key] = withoutUndefined({\n name: phase.name,\n description: phase.description ?? undefined,\n kind: phase.kind,\n nextPhases: storedNextPhases(phase, board.phases),\n runner,\n autoStart: phase.autoStart ? true : undefined,\n autoStartWhen: phase.autoStartWhen ?? undefined,\n exitTool,\n tools: phase.tools?.length ? phase.tools : undefined,\n }) as BoardPhaseDefinition<string>;\n }\n return {\n id: board.key,\n name: board.name,\n ...(board.description != null ? { description: board.description } : {}),\n initialPhase: initial.key,\n phases,\n ...(behaviour?.tools ? { tools: behaviour.tools } : {}),\n ...(behaviour?.events ? { events: behaviour.events } : {}),\n ...(behaviour?.transitionPolicy ? { transitionPolicy: behaviour.transitionPolicy } : {}),\n ...(behaviour?.sourceClosed ? { sourceClosed: behaviour.sourceClosed } : {}),\n };\n}\n\n/** What a code board's behaviour holds fixed on each of its phases; the rest of the phase is editable. */\ninterface CodePhaseBehaviour {\n /** Phases code moves cards to from it; they stay in its nextPhases. */\n requiredNextPhases: string[];\n}\n\n/** The per-phase locks `codeBehaviourConflicts` enforces, for clients that show them. */\nexport function codeBehaviourOf(code: InstalledBoard): Record<string, CodePhaseBehaviour> {\n return Object.fromEntries(\n (Object.entries(code.phases) as [string, BoardPhase<string>][]).map(([key, phase]) => [\n key,\n { requiredNextPhases: [...phase.nextPhases] },\n ]),\n );\n}\n\n/**\n * Why a stored definition of a code board's key can't run with that board's code behaviour, one\n * reason per locked change; empty when it can. Code (tool and event rules, `sourceClosed`,\n * integrations) names the board's phases, its first phase, each phase's kind and the moves it\n * makes between phases, so those stay as code declares them. Names, descriptions, runners, exit\n * tools, phase tools, added moves, start and approval conditions and new phases are free.\n */\nexport function codeBehaviourConflicts(board: StoredBoardInput, code: InstalledBoard): string[] {\n const stored = new Map(board.phases.map(phase => [phase.key, phase]));\n const conflicts: string[] = [];\n if (board.phases[0]?.key !== code.initialPhase) {\n conflicts.push(`Cards on board \"${code.id}\" start in \"${code.initialPhase}\"; keep it the first phase.`);\n }\n for (const [key, phase] of Object.entries(code.phases) as [string, BoardPhase<string>][]) {\n const edited = stored.get(key);\n const label = `Phase \"${key}\"`;\n if (!edited) {\n conflicts.push(`${label} has code behaviour on board \"${code.id}\"; it can't be removed.`);\n continue;\n }\n if (edited.kind !== phase.kind) {\n conflicts.push(`${label} must stay ${phase.kind}; its code behaviour depends on it.`);\n continue;\n }\n const nextPhases = storedNextPhases(edited, board.phases);\n for (const target of phase.nextPhases) {\n if (nextPhases.includes(target)) continue;\n conflicts.push(`${label}: Factory's code moves cards from it to \"${target}\"; keep it in nextPhases.`);\n }\n }\n return conflicts;\n}\n\n/** Whether two storable definitions describe the same board once unset fields and defaults are resolved. */\nexport function sameBoardDefinition(a: StoredBoardInput, b: StoredBoardInput): boolean {\n return (\n canonicalJson(boardDefinitionOf(compileStoredBoard(a))) === canonicalJson(boardDefinitionOf(compileStoredBoard(b)))\n );\n}\n\nfunction canonicalJson(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;\n if (value !== null && typeof value === 'object') {\n const entries = Object.entries(value)\n .filter(([, entry]) => entry !== undefined)\n .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));\n return `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(',')}}`;\n }\n return JSON.stringify(value);\n}\n\n/**\n * A board's storable definition, in the shape the boards API reads and writes. The initial phase\n * comes first and every phase's resolved `nextPhases` is written out.\n */\nexport function boardDefinitionOf(board: InstalledBoard): StoredBoardInput {\n const order = [board.initialPhase, ...Object.keys(board.phases).filter(key => key !== board.initialPhase)];\n return {\n key: board.id,\n name: board.name,\n ...(board.description !== undefined ? { description: board.description } : {}),\n phases: order.map(key => storedPhase(key, board.phases[key]!)),\n };\n}\n\nfunction storedPhase(key: string, phase: BoardPhase<string>): StoredPhaseInput {\n return withoutUndefined({\n key,\n name: phase.name,\n description: phase.description,\n kind: phase.kind,\n nextPhases: [...phase.nextPhases],\n ...(phase.kind === 'working'\n ? {\n runner: withoutUndefined({\n skill: phase.runner.skill,\n context: phase.runner.context,\n instructions: phase.runner.instructions,\n goal: phase.runner.goal ? { ...phase.runner.goal } : undefined,\n }),\n autoStart: phase.autoStart ? true : undefined,\n autoStartWhen: phase.autoStartWhen,\n exitTool: phase.exitTool\n ? withoutUndefined({\n id: phase.exitTool.id,\n autoApprove: phase.exitTool.autoApprove,\n autoApproveWhen: phase.exitTool.autoApproveWhen,\n })\n : undefined,\n tools: phase.tools ? [...phase.tools] : undefined,\n }\n : {}),\n });\n}\n\nfunction withoutUndefined<T extends object>(value: T): T {\n return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)) as T;\n}\n"],"mappings":";;;;AAQA,MAAM,qBAAqB,EACxB,OAAO;CACN,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,cAAc,EAAE,OAAO,CAAC,CAAC,SAAS;CAClC,MAAM,EAAE,OAAO;EAAE,WAAW,EAAE,OAAO;EAAG,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS;AAC9F,CAAC,CAAC,CACD,OAAO;AAEV,MAAM,uBAAuB,EAC1B,OAAO;CACN,IAAI,EAAE,OAAO;CACb,aAAa,EAAE,QAAQ,CAAC,CAAC,SAAS;CAClC,iBAAiB,oBAAoB,SAAS;AAChD,CAAC,CAAC,CACD,OAAO;AAEV,MAAa,yBAAyB,EACnC,OAAO;CACN,KAAK,EAAE,OAAO;CACd,MAAM,EAAE,OAAO;CACf,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ;CAChC,MAAM,EAAE,KAAK;EAAC;EAAW;EAAW;CAAU,CAAC;CAC/C,QAAQ,mBAAmB,QAAQ;CACnC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ;CACxC,WAAW,EAAE,QAAQ,CAAC,CAAC,SAAS;CAChC,eAAe,oBAAoB,QAAQ;CAC3C,UAAU,qBAAqB,QAAQ;CACvC,OAAO,EAAE,MAAM,EAAE,KAAK,mBAAmB,CAAC,CAAC,CAAC,QAAQ;AACtD,CAAC,CAA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,GAAG,WAAW,UAAU,KAAA,CAAS,CAAC;AAC5F"}
@@ -0,0 +1,19 @@
1
+ import type { StoredBoardInput, StoredBoardMigration, StoredBoardRecord, StoredPhaseInput } from '../storage/domains/boards/base.js';
2
+ /**
3
+ * The Work seed this migration fills from: Work as it was while it had its self-review phase.
4
+ * Only projects stored before then hold the old defaults it replaces, and their rows still have
5
+ * that phase, so they get its runner rather than today's seed, which has no such phase.
6
+ */
7
+ export declare function workSeedWithSelfReview(): StoredBoardInput;
8
+ export declare function migrateWorkPhaseRunners(board: StoredBoardRecord, seed?: StoredBoardInput): {
9
+ board: {
10
+ name: string;
11
+ description: string | null;
12
+ phases: StoredPhaseInput[];
13
+ };
14
+ filled: string[];
15
+ } | undefined;
16
+ export declare const WORK_PHASE_RUNNERS_MIGRATION: StoredBoardMigration;
17
+ /** The board migrations each project gets once, in order. */
18
+ export declare const BOARD_MIGRATIONS: readonly StoredBoardMigration[];
19
+ //# sourceMappingURL=work-migrations.d.ts.map