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

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 (197) hide show
  1. package/README.md +52 -28
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +5 -5
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/board-writes.d.ts.map +1 -1
  6. package/dist/boards/board-writes.js +6 -7
  7. package/dist/boards/board-writes.js.map +1 -1
  8. package/dist/boards/index.d.ts +1 -1
  9. package/dist/boards/index.d.ts.map +1 -1
  10. package/dist/boards/index.js +2 -2
  11. package/dist/boards/project-boards.d.ts +30 -4
  12. package/dist/boards/project-boards.d.ts.map +1 -1
  13. package/dist/boards/project-boards.js +71 -19
  14. package/dist/boards/project-boards.js.map +1 -1
  15. package/dist/boards/registry.d.ts +7 -1
  16. package/dist/boards/registry.d.ts.map +1 -1
  17. package/dist/boards/registry.js +16 -3
  18. package/dist/boards/registry.js.map +1 -1
  19. package/dist/boards/semantics.d.ts +5 -4
  20. package/dist/boards/semantics.d.ts.map +1 -1
  21. package/dist/boards/semantics.js +5 -4
  22. package/dist/boards/semantics.js.map +1 -1
  23. package/dist/boards/work-migrations.d.ts +4 -3
  24. package/dist/boards/work-migrations.d.ts.map +1 -1
  25. package/dist/boards/work-migrations.js +6 -5
  26. package/dist/boards/work-migrations.js.map +1 -1
  27. package/dist/boards/work-seeds.d.ts +9 -0
  28. package/dist/boards/work-seeds.d.ts.map +1 -0
  29. package/dist/boards/work-seeds.js +56 -0
  30. package/dist/boards/work-seeds.js.map +1 -0
  31. package/dist/boards/work.d.ts +2 -2
  32. package/dist/boards/work.d.ts.map +1 -1
  33. package/dist/boards/work.js +0 -16
  34. package/dist/boards/work.js.map +1 -1
  35. package/dist/factory.d.ts +8 -4
  36. package/dist/factory.d.ts.map +1 -1
  37. package/dist/factory.js +30 -58
  38. package/dist/factory.js.map +1 -1
  39. package/dist/feed-events.d.ts +2 -3
  40. package/dist/feed-events.d.ts.map +1 -1
  41. package/dist/feed-events.js +4 -5
  42. package/dist/feed-events.js.map +1 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -1
  46. package/dist/integrations/base.d.ts +0 -11
  47. package/dist/integrations/base.d.ts.map +1 -1
  48. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  49. package/dist/integrations/linear/agent-tools.js +1 -1
  50. package/dist/integrations/linear/agent-tools.js.map +1 -1
  51. package/dist/integrations/slack/integration.d.ts +0 -2
  52. package/dist/integrations/slack/integration.d.ts.map +1 -1
  53. package/dist/integrations/slack/integration.js +0 -5
  54. package/dist/integrations/slack/integration.js.map +1 -1
  55. package/dist/integrations/slack/slack.d.ts +3 -18
  56. package/dist/integrations/slack/slack.d.ts.map +1 -1
  57. package/dist/integrations/slack/slack.js +3 -74
  58. package/dist/integrations/slack/slack.js.map +1 -1
  59. package/dist/links.d.ts +1 -2
  60. package/dist/links.d.ts.map +1 -1
  61. package/dist/links.js +1 -2
  62. package/dist/links.js.map +1 -1
  63. package/dist/routes/attention-providers.d.ts +0 -25
  64. package/dist/routes/attention-providers.d.ts.map +1 -1
  65. package/dist/routes/attention-providers.js +2 -150
  66. package/dist/routes/attention-providers.js.map +1 -1
  67. package/dist/routes/attention.d.ts +0 -2
  68. package/dist/routes/attention.d.ts.map +1 -1
  69. package/dist/routes/attention.js +2 -13
  70. package/dist/routes/attention.js.map +1 -1
  71. package/dist/routes/contracts.d.ts +6 -14
  72. package/dist/routes/contracts.d.ts.map +1 -1
  73. package/dist/routes/contracts.js +4 -2
  74. package/dist/routes/contracts.js.map +1 -1
  75. package/dist/routes/feed-events.d.ts +15 -0
  76. package/dist/routes/feed-events.d.ts.map +1 -0
  77. package/dist/routes/feed-events.js +68 -0
  78. package/dist/routes/feed-events.js.map +1 -0
  79. package/dist/routes/knowledge.js +1 -1
  80. package/dist/routes/projects.d.ts +1 -1
  81. package/dist/routes/projects.d.ts.map +1 -1
  82. package/dist/routes/projects.js +1 -1
  83. package/dist/routes/projects.js.map +1 -1
  84. package/dist/routes/surface.d.ts +0 -7
  85. package/dist/routes/surface.d.ts.map +1 -1
  86. package/dist/routes/surface.js +1 -5
  87. package/dist/routes/surface.js.map +1 -1
  88. package/dist/routes/work-items.d.ts +0 -3
  89. package/dist/routes/work-items.d.ts.map +1 -1
  90. package/dist/routes/work-items.js +0 -1
  91. package/dist/routes/work-items.js.map +1 -1
  92. package/dist/rules/dispatcher.d.ts +0 -3
  93. package/dist/rules/dispatcher.d.ts.map +1 -1
  94. package/dist/rules/dispatcher.js +5 -7
  95. package/dist/rules/dispatcher.js.map +1 -1
  96. package/dist/storage/domains/audit/actions.d.ts +1 -1
  97. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  98. package/dist/storage/domains/audit/actions.js +0 -4
  99. package/dist/storage/domains/audit/actions.js.map +1 -1
  100. package/dist/storage/domains/boards/base.d.ts +15 -1
  101. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  102. package/dist/storage/domains/boards/base.js +21 -5
  103. package/dist/storage/domains/boards/base.js.map +1 -1
  104. package/dist/storage/domains/channel-identity/base.d.ts +0 -4
  105. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
  106. package/dist/storage/domains/channel-identity/base.js +0 -7
  107. package/dist/storage/domains/channel-identity/base.js.map +1 -1
  108. package/dist/storage/domains/work-items/base.d.ts +6 -8
  109. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  110. package/dist/storage/domains/work-items/base.js +9 -84
  111. package/dist/storage/domains/work-items/base.js.map +1 -1
  112. package/dist/storage/domains/work-items/cards.d.ts +3 -3
  113. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  114. package/dist/storage/domains/work-items/cards.js +10 -10
  115. package/dist/storage/domains/work-items/cards.js.map +1 -1
  116. package/dist/storage/domains/work-items/work-item-schema.d.ts +1 -2
  117. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  118. package/dist/storage/domains/work-items/work-item-schema.js +8 -8
  119. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  120. package/dist/tools/read-tools.d.ts +0 -2
  121. package/dist/tools/read-tools.d.ts.map +1 -1
  122. package/dist/tools/read-tools.js +3 -14
  123. package/dist/tools/read-tools.js.map +1 -1
  124. package/dist/tools/work-item-tools.d.ts +0 -3
  125. package/dist/tools/work-item-tools.d.ts.map +1 -1
  126. package/dist/tools/work-item-tools.js +8 -18
  127. package/dist/tools/work-item-tools.js.map +1 -1
  128. package/dist/work-items/create-work-item.d.ts.map +1 -1
  129. package/dist/work-items/create-work-item.js +3 -2
  130. package/dist/work-items/create-work-item.js.map +1 -1
  131. package/dist/work-items/description-context.d.ts +5 -0
  132. package/dist/work-items/description-context.d.ts.map +1 -0
  133. package/dist/work-items/description-context.js +17 -0
  134. package/dist/work-items/description-context.js.map +1 -0
  135. package/dist/work-items/split-migration.d.ts.map +1 -1
  136. package/dist/work-items/split-migration.js +1 -6
  137. package/dist/work-items/split-migration.js.map +1 -1
  138. package/factory-skills/configure-factory-rules/SKILL.md +3 -3
  139. package/factory-skills/factory-rereview/SKILL.md +2 -2
  140. package/factory-skills/factory-review/SKILL.md +2 -2
  141. package/factory-skills/factory-triage/SKILL.md +3 -2
  142. package/package.json +6 -6
  143. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
  144. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
  145. package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
  146. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
  147. package/dist/integrations/slack/emoji.d.ts +0 -3
  148. package/dist/integrations/slack/emoji.d.ts.map +0 -1
  149. package/dist/integrations/slack/emoji.js +0 -11
  150. package/dist/integrations/slack/emoji.js.map +0 -1
  151. package/dist/integrations/slack/feed-publisher.d.ts +0 -26
  152. package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
  153. package/dist/integrations/slack/feed-publisher.js +0 -43
  154. package/dist/integrations/slack/feed-publisher.js.map +0 -1
  155. package/dist/routes/attention-activity.d.ts +0 -23
  156. package/dist/routes/attention-activity.d.ts.map +0 -1
  157. package/dist/routes/attention-activity.js +0 -154
  158. package/dist/routes/attention-activity.js.map +0 -1
  159. package/dist/storage/domains/comments/activity.d.ts +0 -40
  160. package/dist/storage/domains/comments/activity.d.ts.map +0 -1
  161. package/dist/storage/domains/comments/activity.js +0 -93
  162. package/dist/storage/domains/comments/activity.js.map +0 -1
  163. package/dist/storage/domains/comments/actor.d.ts +0 -51
  164. package/dist/storage/domains/comments/actor.d.ts.map +0 -1
  165. package/dist/storage/domains/comments/actor.js +0 -37
  166. package/dist/storage/domains/comments/actor.js.map +0 -1
  167. package/dist/storage/domains/comments/base.d.ts +0 -245
  168. package/dist/storage/domains/comments/base.d.ts.map +0 -1
  169. package/dist/storage/domains/comments/base.js +0 -539
  170. package/dist/storage/domains/comments/base.js.map +0 -1
  171. package/dist/storage/domains/comments/domain.d.ts +0 -135
  172. package/dist/storage/domains/comments/domain.d.ts.map +0 -1
  173. package/dist/storage/domains/comments/domain.js +0 -284
  174. package/dist/storage/domains/comments/domain.js.map +0 -1
  175. package/dist/storage/domains/comments/feed-context.d.ts +0 -22
  176. package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
  177. package/dist/storage/domains/comments/feed-context.js +0 -88
  178. package/dist/storage/domains/comments/feed-context.js.map +0 -1
  179. package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
  180. package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
  181. package/dist/storage/domains/comments/feed-sync.js +0 -1
  182. package/dist/storage/domains/comments/parse.d.ts +0 -23
  183. package/dist/storage/domains/comments/parse.d.ts.map +0 -1
  184. package/dist/storage/domains/comments/parse.js +0 -89
  185. package/dist/storage/domains/comments/parse.js.map +0 -1
  186. package/dist/storage/domains/comments/routes.d.ts +0 -24
  187. package/dist/storage/domains/comments/routes.d.ts.map +0 -1
  188. package/dist/storage/domains/comments/routes.js +0 -301
  189. package/dist/storage/domains/comments/routes.js.map +0 -1
  190. package/dist/storage/domains/comments/schema.d.ts +0 -5
  191. package/dist/storage/domains/comments/schema.d.ts.map +0 -1
  192. package/dist/storage/domains/comments/schema.js +0 -178
  193. package/dist/storage/domains/comments/schema.js.map +0 -1
  194. package/dist/storage/domains/comments/wire.d.ts +0 -40
  195. package/dist/storage/domains/comments/wire.d.ts.map +0 -1
  196. package/dist/storage/domains/comments/wire.js +0 -36
  197. package/dist/storage/domains/comments/wire.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"semantics.d.ts","sourceRoot":"","sources":["../../src/boards/semantics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAI3F,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAEf,cAAc,EACd,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAInE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,iFAAiF;IACjF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,CAElE;AAID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAA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BAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAU3G"}
@@ -1,5 +1,5 @@
1
1
  import { workItemBranch, workItemBranchSource } from "../work-item-branch.js";
2
- import { DEFAULT_BOARD_ID } from "./default-board.js";
2
+ import "./default-board.js";
3
3
  import "./define-board.js";
4
4
  import { reviewBoard } from "./review.js";
5
5
  import { workBoard } from "./work.js";
@@ -68,11 +68,12 @@ function boardFlow(board) {
68
68
  return flow;
69
69
  }
70
70
  /**
71
- * Where integrations file new items: the project's default board's initial phase, from which its
72
- * intake routes place them. Undefined when the default board is not installed.
71
+ * Where integrations file new items, and where one lands when no intake route takes it: the
72
+ * project's Work board's initial phase, else (a project an app gave only its own boards) the
73
+ * initial phase of its first board in catalog order. Undefined only for a project with no boards.
73
74
  */
74
75
  function intakeTarget(boards) {
75
- const target = boards.get(DEFAULT_BOARD_ID);
76
+ const target = boards.get("work") ?? boards.values().next().value;
76
77
  if (!target) return void 0;
77
78
  return Object.freeze({
78
79
  board: target.id,
@@ -1 +1 @@
1
- {"version":3,"file":"semantics.js","names":[],"sources":["../../src/boards/semantics.ts"],"sourcesContent":["import type {\n FactoryRuleBoardClosure,\n FactoryRuleBoardFlow,\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 integrations file new items: the project's default board's initial phase, from which its\n * intake routes place them. Undefined when the default board is not installed.\n */\nexport function intakeTarget(boards: Pick<BoardRegistry, 'get'>): FactoryRuleIntakeTarget | undefined {\n const target = boards.get(DEFAULT_BOARD_ID);\n if (!target) return undefined;\n return Object.freeze({ board: target.id, initialPhase: target.initialPhase });\n}\n\n/** {@link intakeTarget} as a rule context field. */\nexport function withIntakeTarget(boards: Pick<BoardRegistry, 'get'>): { intake?: FactoryRuleIntakeTarget } {\n const intake = intakeTarget(boards);\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,uBAAuB,CAAC,CAAC,GAAG;CAChG,MAAM,aAAa,QAAQ,MACxB,CAAC,KAAK,WACL,QAAQ,qBACR,OAAO,OAAO,+BAA+B,KAC7C,CAAC,OAAO,OAAO,uBAAuB,CAC1C,CAAC,GAAG;CACJ,MAAM,UAAU,cAAc;CAC9B,MAAM,QAAQ,UACV,QAAQ,UACL,CAAC,KAAK,WACL,MAAM,SAAS,aACf,QAAQ,qBACR,QAAQ,cACR,MAAM,iBAAiB,KAAK,OAAO,CACvC,CAAC,GAAG,KACJ,KAAA;CACJ,MAAM,YAAY,QAAQ,MAAM,aAAa,KAAK,IAAI,KAAA;CAEtD,MAAM,SAAS,QACX,QAAQ,MACL,CAAC,KAAK,WACL,MAAM,SAAS,aACf,QAAQ,SACR,MAAM,OAAO,YAAA,YACb,MAAM,OAAO,YAAY,SAC7B,CAAC,GAAG,KACJ,KAAA;C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,CAAE;EAAK;EACpE,UAAU;GAAE,OAAO;GAAU,OAAO,MAAM,OAAO,SAAS,CAAE;EAAK;EACjE,cAAc,KAAK,OAAO,MAAK,UAAS,MAAM,WAAW,KAAK,CAAC;CACjE;AACF;;AAGA,SAAgB,iBACd,QACA,MAC4C;CAC5C,MAAM,eAAe,oBAAoB,QAAQ,IAAI;CACrD,OAAO,eAAe,EAAE,aAAa,IAAI,CAAC;AAC5C;;AAGA,SAAgB,eACd,QACA,MAC8C;CAC9C,MAAM,QAAQ,iBAAiB,QAAQ,IAAI;CAC3C,OAAO,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B;;;;;AAMA,SAAgB,yBAAyB,QAAoC,MAAgC;CAC3G,MAAM,SAAS,qBAAqB,KAAK,cAAc;CAEvD,IAAI,CADQ,kBAAkB,EAAE,OAAO,CAChC,MAAM,KAAK,OAAO,WAAW,KAAK,cAAc,QAAQ,IAAI,CAAC,CAAC,sBAAsB,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"}
1
+ {"version":3,"file":"semantics.js","names":[],"sources":["../../src/boards/semantics.ts"],"sourcesContent":["import type {\n FactoryRuleBoardClosure,\n FactoryRuleBoardFlow,\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 integrations file new items, and where one lands when no intake route takes it: the\n * project's Work board's initial phase, else (a project an app gave only its own boards) the\n * initial phase of its first board in catalog order. Undefined only for a project with no boards.\n */\nexport function intakeTarget(boards: Pick<BoardRegistry, 'get' | 'values'>): FactoryRuleIntakeTarget | undefined {\n const target = boards.get(DEFAULT_BOARD_ID) ?? boards.values().next().value;\n if (!target) return undefined;\n return Object.freeze({ board: target.id, initialPhase: target.initialPhase });\n}\n\n/** {@link intakeTarget} as a rule context field. */\nexport function withIntakeTarget(boards: Pick<BoardRegistry, 'get' | 'values'>): { intake?: FactoryRuleIntakeTarget } {\n const intake = intakeTarget(boards);\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,uBAAuB,CAAC,CAAC,GAAG;CAChG,MAAM,aAAa,QAAQ,MACxB,CAAC,KAAK,WACL,QAAQ,qBACR,OAAO,OAAO,+BAA+B,KAC7C,CAAC,OAAO,OAAO,uBAAuB,CAC1C,CAAC,GAAG;CACJ,MAAM,UAAU,cAAc;CAC9B,MAAM,QAAQ,UACV,QAAQ,UACL,CAAC,KAAK,WACL,MAAM,SAAS,aACf,QAAQ,qBACR,QAAQ,cACR,MAAM,iBAAiB,KAAK,OAAO,CACvC,CAAC,GAAG,KACJ,KAAA;CACJ,MAAM,YA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;AAOA,SAAgB,oBACd,QACA,MACqC;CACrC,MAAM,QAAQ,OAAO,IAAI,iBAAiB,IAAI,CAAC;CAC/C,IAAI,CAAC,OAAO,cAAc,OAAO,KAAA;CACjC,MAAM,EAAE,WAAW,aAAa,MAAM;CACtC,OAAO;EACL,YAAY,MAAM;EAClB,WAAW;GAAE,OAAO;GAAW,OAAO,MAAM,OAAO,UAAU,CAAE;EAAK;EACpE,UAAU;GAAE,OAAO;GAAU,OAAO,MAAM,OAAO,SAAS,CAAE;EAAK;EACjE,cAAc,KAAK,OAAO,MAAK,UAAS,MAAM,WAAW,KAAK,CAAC;CACjE;AACF;;AAGA,SAAgB,iBACd,QACA,MAC4C;CAC5C,MAAM,eAAe,oBAAoB,QAAQ,IAAI;CACrD,OAAO,eAAe,EAAE,aAAa,IAAI,CAAC;AAC5C;;AAGA,SAAgB,eACd,QACA,MAC8C;CAC9C,MAAM,QAAQ,iBAAiB,QAAQ,IAAI;CAC3C,OAAO,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B;;;;;AAMA,SAAgB,yBAAyB,QAAoC,MAAgC;CAC3G,MAAM,SAAS,qBAAqB,KAAK,cAAc;CAEvD,IAAI,CADQ,kBAAkB,EAAE,OAAO,CAChC,MAAM,KAAK,OAAO,WAAW,KAAK,cAAc,QAAQ,IAAI,CAAC,CAAC,sBAAsB,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"}
@@ -1,8 +1,9 @@
1
1
  import type { BoardMigrationContext, StoredBoardInput, StoredBoardMigration, StoredBoardRecord, StoredPhaseInput } from '../storage/domains/boards/base.js';
2
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.
3
+ * The Work seed this migration fills from: Work as it was while it had its self-review phase and
4
+ * Triage. Only projects stored before then hold the old defaults it replaces, and their rows still
5
+ * have those phases, so they get their runners (and keep their moves into Triage) rather than
6
+ * today's seed, which has neither.
6
7
  */
7
8
  export declare function workSeedWithSelfReview(): StoredBoardInput;
8
9
  export declare function migrateWorkPhaseRunners(board: StoredBoardRecord, seed?: StoredBoardInput): {
@@ -1 +1 @@
1
- {"version":3,"file":"work-migrations.d.ts","sourceRoot":"","sources":["../../src/boards/work-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,mCAAmC,CAAC;AA8D3C;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAwBzD;AAwED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,iBAAiB,EACxB,IAAI,mBAA2B,GAC9B;IAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CAqDnH;AAED,eAAO,MAAM,4BAA4B,EAAE,oBAI1C,CAAC;AA8BF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,qBAAqB,GAC7B;IAAE,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CA+BxE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,qBAAqB,G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,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,SAAS,CAWxE;AAED,eAAO,MAAM,qBAAqB,EAAE,oBAInC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,oBAIhC,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,EAAE,SAAS,oBAAoB,EAI3D,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import "./define-board.js";
2
- import { boardDefinitionOf } from "./stored-board.js";
2
+ import { workSeedWithTriage } from "./work-seeds.js";
3
3
  import { OWN_CARD_HAND_OFF, workBoard } from "./work.js";
4
4
  // src/boards/work-migrations.ts
5
5
  const MIGRATED_FIELDS = [
@@ -92,12 +92,13 @@ const OLD_WORK_SEED = {
92
92
  /** Building's goal while Work still had its self-review phase. */
93
93
  const SELF_REVIEW_BUILD_OBJECTIVE = "Build the plan approved in Planning for this work item. Done when every step of that plan is implemented on the work branch; the plan's verification gates (the tests, typecheck and lint it names, else the narrowest relevant ones) were run on the final head and passed; the branch is pushed; and the card was moved on with factory_transition_work_item out of Building (to Review or PR review as the builder's hand-off says, or back to Planning if the plan proved wrong); the builder's latest message names the move and the pushed head. " + OWN_CARD_HAND_OFF + " Continue while any of that is missing. Waiting only when the agent asked a person a question it cannot answer from the repository.";
94
94
  /**
95
- * The Work seed this migration fills from: Work as it was while it had its self-review phase.
96
- * Only projects stored before then hold the old defaults it replaces, and their rows still have
97
- * that phase, so they get its runner rather than today's seed, which has no such phase.
95
+ * The Work seed this migration fills from: Work as it was while it had its self-review phase and
96
+ * Triage. Only projects stored before then hold the old defaults it replaces, and their rows still
97
+ * have those phases, so they get their runners (and keep their moves into Triage) rather than
98
+ * today's seed, which has neither.
98
99
  */
99
100
  function workSeedWithSelfReview() {
100
- const seed = boardDefinitionOf(workBoard);
101
+ const seed = workSeedWithTriage();
101
102
  const phases = seed.phases.flatMap((phase) => {
102
103
  if (phase.key !== "execute") return [phase];
103
104
  const goal = phase.runner?.goal && {
@@ -1 +1 @@
1
- {"version":3,"file":"work-migrations.js","names":[],"sources":["../../src/boards/work-migrations.ts"],"sourcesContent":["import type {\n BoardMigrationContext,\n StoredBoardInput,\n StoredBoardMigration,\n StoredBoardRecord,\n StoredPhaseInput,\n StoredPhaseRecord,\n} from '../storage/domains/boards/base.js';\nimport { REVIEW_CONTEXT } from './define-board.js';\nimport type { FactoryPhaseTool } from './define-board.js';\nimport { boardDefinitionOf } from './stored-board.js';\nimport { OWN_CARD_HAND_OFF, workBoard } from './work.js';\n\nconst MIGRATED_FIELDS = ['runner', 'exitTool', 'tools', 'autoStart', 'autoStartWhen', 'nextPhases'] as const;\ntype MigratedField = (typeof MIGRATED_FIELDS)[number];\n\nconst PHASE_DEFAULTS = { exitTool: [null], tools: [null], autoStart: [null], autoStartWhen: [null] } as const;\n\n/**\n * What Factory stored for Work's working phases before they had runners: the seed of #29317, and\n * #29346's for the `nextPhases` it changed. Frozen: a value listed here is one a project can only\n * hold because Factory wrote it, so the migration may replace it.\n */\nconst OLD_WORK_SEED: Readonly<Record<string, Readonly<Record<MigratedField, readonly unknown[]>>>> = {\n triage: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'triage' }],\n nextPhases: [['intake', 'planning', 'done', 'canceled']],\n },\n planning: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n exitTool: [{ id: 'submit_plan', autoApprove: false }],\n nextPhases: [['execute', 'triage', 'intake', 'done', 'canceled']],\n },\n execute: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [['review', 'planning', 'done', 'canceled']],\n },\n review: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [\n ['execute', 'intake', 'done', 'canceled'],\n ['execute', 'intake', 'pr-review', 'done', 'canceled'],\n ],\n },\n 'pr-review': {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [\n ['intake', 'done', 'canceled'],\n ['intake', 'planning', 'execute', 'done', 'canceled'],\n ],\n },\n};\n\n/** Building's goal while Work still had its self-review phase. */\nconst SELF_REVIEW_BUILD_OBJECTIVE =\n 'Build the plan approved in Planning for this work item. Done when every step of that plan is implemented on ' +\n \"the work branch; the plan's verification gates (the tests, typecheck and lint it names, else the narrowest \" +\n 'relevant ones) were run on the final head and passed; the branch is pushed; and the card was moved on with ' +\n \"factory_transition_work_item out of Building (to Review or PR review as the builder's hand-off says, or back to \" +\n \"Planning if the plan proved wrong); the builder's latest message names the move and the pushed head. \" +\n OWN_CARD_HAND_OFF +\n ' Continue while any of that is missing. Waiting only when the agent asked a person a question it cannot ' +\n 'answer from the repository.';\n\n/**\n * The Work seed this migration fills from: Work as it was while it had its self-review phase.\n * Only projects stored before then hold the old defaults it replaces, and their rows still have\n * that phase, so they get its runner rather than today's seed, which has no such phase.\n */\nexport function workSeedWithSelfReview(): StoredBoardInput {\n const seed = boardDefinitionOf(workBoard);\n const phases = seed.phases.flatMap((phase): StoredPhaseInput[] => {\n if (phase.key !== 'execute') return [phase];\n const goal = phase.runner?.goal && { ...phase.runner.goal, objective: SELF_REVIEW_BUILD_OBJECTIVE };\n return [\n {\n ...phase,\n runner: { ...phase.runner, ...(goal ? { goal } : {}) },\n nextPhases: ['review', 'pr-review', 'planning', 'done', 'canceled'],\n },\n {\n key: 'review',\n name: 'Review',\n kind: 'working',\n runner: { skill: 'factory-self-review', context: 'review' },\n autoStart: true,\n autoStartWhen: { operator: 'AND', conditions: [{ field: 'item.pullRequest', operator: 'not_exists' }] },\n tools: ['factory_record_review_verdict'],\n nextPhases: ['execute', 'intake', 'pr-review', 'done', 'canceled'],\n },\n ];\n });\n return { ...seed, phases };\n}\n\n/** Stable JSON with sorted keys; an unset field, `null`, `false` and no tools all read the same. */\nfunction canonical(field: MigratedField, value: unknown): string {\n if (value === undefined || value === null || value === false) return 'null';\n if (field === 'tools' && Array.isArray(value) && value.length === 0) return 'null';\n return JSON.stringify(sorted(value));\n}\n\nfunction sorted(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(sorted);\n if (value === null || typeof value !== 'object') return value;\n return Object.fromEntries(\n Object.entries(value)\n .filter(([, entry]) => entry !== undefined)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => [key, sorted(entry)]),\n );\n}\n\nfunction toInput({ position: _position, ...phase }: StoredPhaseRecord): StoredPhaseInput {\n return phase;\n}\n\n/** Whether Factory may write the new value over the stored one: the stored one is still an old default. */\nfunction stillOldDefault(phaseKey: string, field: MigratedField, stored: unknown): boolean {\n const old = OLD_WORK_SEED[phaseKey]?.[field] ?? [];\n const current = canonical(field, stored);\n return old.some(value => canonical(field, value) === current);\n}\n\n/**\n * Gives a project's stored Work board the phase runners, goal, automatic starts and phase tools\n * of Factory's Work seed, field by field: only a field that still holds the value Factory\n * stored before is filled, so every field a person edited stays as they left it. A phase the\n * row lacks, or holds as another kind, is left alone, as is a move to a phase the row lacks.\n */\ntype StoredRunner = StoredPhaseInput['runner'];\n\n/**\n * The seed's runner parts a stored runner still lacks or holds at the old default: `context` when\n * it is the old seed's, `skill` and `goal` when unset (the old seed set neither). Instructions and\n * any part a person set stay as they are.\n */\nfunction migrateRunner(\n phaseKey: string,\n stored: StoredRunner,\n target: StoredRunner,\n): { value: NonNullable<StoredRunner>; filled: string[] } | undefined {\n if (!target) return undefined;\n const value: NonNullable<StoredRunner> = { ...(stored ?? {}) };\n const filled: string[] = [];\n const oldContexts = (OLD_WORK_SEED[phaseKey]?.runner ?? []).map(old => (old as { context?: string }).context);\n if (\n target.context !== undefined &&\n value.context !== target.context &&\n (value.context === undefined || oldContexts.includes(value.context))\n ) {\n value.context = target.context;\n filled.push('context');\n }\n if (target.skill !== undefined && value.skill === undefined) {\n value.skill = target.skill;\n filled.push('skill');\n }\n if (target.goal !== undefined && value.goal === undefined) {\n value.goal = target.goal;\n filled.push('goal');\n }\n return filled.length > 0 ? { value, filled } : undefined;\n}\n\nexport function migrateWorkPhaseRunners(\n board: StoredBoardRecord,\n seed = workSeedWithSelfReview(),\n): { board: { name: string; description: string | null; phases: StoredPhaseInput[] }; filled: string[] } | undefined {\n const phaseKeys = new Set(board.phases.map(phase => phase.key));\n const filled: string[] = [];\n const phases = board.phases.map(record => {\n const phase = toInput(record);\n const target = seed.phases.find(candidate => candidate.key === phase.key);\n if (!target || target.kind !== phase.kind || !OLD_WORK_SEED[phase.key]) return phase;\n const next: StoredPhaseInput = { ...phase };\n // The runner is migrated part by part: a person who only wrote instructions (the one part the\n // old seed left editable) still gets the skill, goal and context, and keeps the instructions.\n const runner = migrateRunner(phase.key, phase.runner, target.runner);\n if (runner) {\n next.runner = runner.value;\n filled.push(...runner.filled.map(part => `${phase.key}.runner.${part}`));\n }\n for (const field of MIGRATED_FIELDS) {\n if (field === 'runner') continue;\n const value = target[field] ?? null;\n if (canonical(field, value) === canonical(field, phase[field])) continue;\n if (!stillOldDefault(phase.key, field, phase[field])) continue;\n if (field === 'nextPhases' && !(value as string[]).every(key => phaseKeys.has(key))) continue;\n Object.assign(next, { [field]: value });\n filled.push(`${phase.key}.${field}`);\n }\n const moves = next.nextPhases ?? [...phaseKeys].filter(key => key !== phase.key);\n const revert = (field: MigratedField) => {\n if (!filled.includes(`${phase.key}.${field}`)) return;\n Object.assign(next, { [field]: phase[field] });\n filled.splice(filled.indexOf(`${phase.key}.${field}`), 1);\n };\n // The seed's goal is done only once the card moved on along the seed's moves (Building to PR\n // review, say): a phase whose moves a person narrowed runs the skill without the goal, rather\n // than judging a goal it may never meet.\n const seedMoves = (target.nextPhases ?? []).filter(key => phaseKeys.has(key));\n if (\n filled.includes(`${phase.key}.runner.goal`) &&\n next.runner?.goal &&\n !seedMoves.every(key => moves.includes(key))\n ) {\n const { goal: _goal, ...runner } = next.runner;\n next.runner = runner;\n }\n // Auto-start and Factory tools serve the seed's skill; a phase running another skill keeps its own.\n if (next.runner?.skill !== target.runner?.skill || next.runner?.context !== target.runner?.context) {\n for (const field of ['tools', 'autoStart', 'autoStartWhen'] as const) revert(field);\n }\n if (filled.includes(`${phase.key}.runner.goal`) && !next.runner?.goal) {\n filled.splice(filled.indexOf(`${phase.key}.runner.goal`), 1);\n }\n return next;\n });\n if (filled.length === 0) return undefined;\n return { board: { name: board.name, description: board.description, phases }, filled };\n}\n\nexport const WORK_PHASE_RUNNERS_MIGRATION: StoredBoardMigration = {\n key: 'work-phase-runners-v1',\n boardKey: workBoard.id,\n migrate: board => migrateWorkPhaseRunners(board),\n};\n\n/**\n * The board's review phases as {@link boardFlow} finds them: `pullRequestReview` is the first\n * review-seat phase granting `factory_review_source`; `selfReview` the first other one granting\n * `factory_record_review_verdict` and not `factory_review_source`; `build` the last other working\n * phase that moves into self-review.\n */\nfunction reviewPhases(board: StoredBoardRecord) {\n const grants = (phase: StoredPhaseRecord, tool: FactoryPhaseTool) =>\n phase.kind === 'working' && phase.runner?.context === REVIEW_CONTEXT && (phase.tools ?? []).includes(tool);\n const pullRequestReview = board.phases.find(phase => grants(phase, 'factory_review_source'));\n const selfReview = board.phases.find(\n phase =>\n phase !== pullRequestReview &&\n grants(phase, 'factory_record_review_verdict') &&\n !grants(phase, 'factory_review_source'),\n );\n const build = selfReview\n ? board.phases.findLast(\n phase =>\n phase.kind === 'working' &&\n phase !== pullRequestReview &&\n phase !== selfReview &&\n (phase.nextPhases ?? []).includes(selfReview.key),\n )\n : undefined;\n return { pullRequestReview, selfReview, build };\n}\n\n/**\n * Carries a project's retired self-review switch into its boards: with the switch off, a card went\n * past any board's self-review phase, so the phase goes, with every move into it. A board is left\n * as it is, with a warning, when its code board declares the phase (without it the board would run\n * without its code rules), when cards sit in the phase (removing it would strand them), when its\n * build phase could only reach the pull request review through it, or when it is another phase's\n * only move.\n */\nexport function migrateSelfReviewSwitch(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined {\n if (!context.retiredSettings || context.retiredSettings.selfReviewEnabled) return undefined;\n const { pullRequestReview, selfReview, build } = reviewPhases(board);\n if (!selfReview) return undefined;\n const phase = selfReview.key;\n const keep = (reason: string) => {\n context.warn(\n `Board \"${board.key}\" keeps its self-review phase \"${phase}\": ${reason}. The project's self-review ` +\n 'setting was off; remove the phase to keep skipping self-review.',\n );\n return undefined;\n };\n if (context.codePhases(board.key)?.has(phase)) return keep('its code declares it, so remove it in code first');\n // Without the cards it could strand some in the phase: the project's next load runs it again.\n if (!context.occupiedPhases) throw new Error(\"the project's cards can't be read yet\");\n if (context.occupiedPhases.get(board.key)?.has(phase)) return keep('cards sit in it, move them first');\n if (build && !(pullRequestReview && (build.nextPhases ?? []).includes(pullRequestReview.key))) {\n return keep(`\"${build.key}\" can't move to a pull request review without it, add that move first`);\n }\n const stranded = board.phases.find(\n record => record.key !== phase && record.nextPhases?.length && record.nextPhases.every(key => key === phase),\n );\n if (stranded) return keep(`it is the only move out of \"${stranded.key}\", give that phase another move first`);\n const phases = board.phases\n .filter(record => record.key !== phase)\n .map(record => {\n const next = toInput(record);\n if (next.nextPhases) next.nextPhases = next.nextPhases.filter(key => key !== phase);\n return next;\n });\n return { board: { name: board.name, description: board.description, phases }, filled: [`${phase} removed`] };\n}\n\n/**\n * Carries a project's retired auto-run switch into its boards: with it on, every run started\n * without a person, so every working phase starts on its own, for every card (`autoStartWhen`\n * cleared). With it off a run started on its own only where the phase said so, as it does now.\n */\nexport function migrateAutoRunSwitch(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined {\n if (!context.retiredSettings?.autoRunEnabled) return undefined;\n const filled: string[] = [];\n const phases = board.phases.map(record => {\n const phase = toInput(record);\n if (phase.kind !== 'working' || (phase.autoStart && !phase.autoStartWhen)) return phase;\n filled.push(`${phase.key}.autoStart`);\n return { ...phase, autoStart: true, autoStartWhen: null };\n });\n if (filled.length === 0) return undefined;\n return { board: { name: board.name, description: board.description, phases }, filled };\n}\n\nexport const SELF_REVIEW_MIGRATION: StoredBoardMigration = {\n key: 'self-review-switch-v1',\n boardKey: null,\n migrate: migrateSelfReviewSwitch,\n};\n\nexport const AUTO_RUN_MIGRATION: StoredBoardMigration = {\n key: 'auto-run-switch-v1',\n boardKey: null,\n migrate: migrateAutoRunSwitch,\n};\n\n/** The board migrations each project gets once, in order. */\nexport const BOARD_MIGRATIONS: readonly StoredBoardMigration[] = [\n WORK_PHASE_RUNNERS_MIGRATION,\n SELF_REVIEW_MIGRATION,\n AUTO_RUN_MIGRATION,\n];\n"],"mappings":";;;;AAaA,MAAM,kBAAkB;CAAC;CAAU;CAAY;CAAS;CAAa;CAAiB;AAAY;AAGlG,MAAM,iBAAiB;CAAE,UAAU,CAAC,IAAI;CAAG,OAAO,CAAC,IAAI;CAAG,WAAW,CAAC,IAAI;CAAG,eAAe,CAAC,IAAI;AAAE;;;;;;AAOnG,MAAM,gBAA+F;CACnG,QAAQ;EACN,GAAG;EACH,QAAQ,CAAC,EAAE,SAAS,SAAS,CAAC;EAC9B,YAAY,CAAC;GAAC;GAAU;GAAY;GAAQ;EAAU,CAAC;CACzD;CACA,UAAU;EACR,GAAG;EACH,QAAQ,CAAC,EAAE,SAAS,OAAO,CAAC;EAC5B,UAAU,CAAC;GAAE,IAAI;GAAe,aAAa;EAAM,CAAC;EACpD,YAAY,CAAC;GAAC;GAAW;GAAU;GAAU;GAAQ;EAAU,CAAC;CAClE;CACA,SAAS;EACP,GAAG;EACH,QAAQ,CAAC,EAAE,SAAS,OAAO,CAAC;EAC5B,YAAY,CAAC;GAAC;GAAU;GAAY;GAAQ;EAAU,CAAC;CACzD;CACA,QAAQ;EACN,GAAG;EACH,QAAQ,CAAC,EAAE,SAAS,OAAO,CAAC;EAC5B,YAAY,CACV;GAAC;GAAW;GAAU;GAAQ;EAAU,GACxC;GAAC;GAAW;GAAU;GAAa;GAAQ;EAAU,CACvD;CACF;CACA,aAAa;EACX,GAAG;EACH,QAAQ,CAAC,EAAE,SAAS,OAAO,CAAC;EAC5B,YAAY,CACV;GAAC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AAO;EAAE,OAAO;GAAE,MAAM,MAAM;GAAM,aAAa,MAAM;GAAa;EAAO;EAAG,QAAQ,CAAC,GAAG,MAAM,SAAS;CAAE;AAC7G;;;;;;AAOA,SAAgB,qBACd,OACA,SACwE;CACxE,IAAI,CAAC,QAAQ,iBAAiB,gBAAgB,OAAO,KAAA;CACrD,MAAM,SAAmB,CAAC;CAC1B,MAAM,SAAS,MAAM,OAAO,KAAI,WAAU;EACxC,MAAM,QAAQ,QAAQ,MAAM;EAC5B,IAAI,MAAM,SAAS,aAAc,MAAM,aAAa,CAAC,MAAM,eAAgB,OAAO;EAClF,OAAO,KAAK,GAAG,MAAM,IAAI,WAAW;EACpC,OAAO;GAAE,GAAG;GAAO,WAAW;GAAM,eAAe;EAAK;CAC1D,CAAC;CACD,IAAI,OAAO,WAAW,GAAG,OAAO,KAAA;CAChC,OAAO;EAAE,OAAO;GAAE,MAAM,MAAM;GAAM,aAAa,MAAM;GAAa;EAAO;EAAG;CAAO;AACvF;AAEA,MAAa,wBAA8C;CACzD,KAAK;CACL,UAAU;CACV,SAAS;AACX;AAEA,MAAa,qBAA2C;CACtD,KAAK;CACL,UAAU;CACV,SAAS;AACX;;AAGA,MAAa,mBAAoD;CAC/D;CACA;CACA;AACF"}
1
+ {"version":3,"file":"work-migrations.js","names":[],"sources":["../../src/boards/work-migrations.ts"],"sourcesContent":["import type {\n BoardMigrationContext,\n StoredBoardInput,\n StoredBoardMigration,\n StoredBoardRecord,\n StoredPhaseInput,\n StoredPhaseRecord,\n} from '../storage/domains/boards/base.js';\nimport { REVIEW_CONTEXT } from './define-board.js';\nimport type { FactoryPhaseTool } from './define-board.js';\nimport { workSeedWithTriage } from './work-seeds.js';\nimport { OWN_CARD_HAND_OFF, workBoard } from './work.js';\n\nconst MIGRATED_FIELDS = ['runner', 'exitTool', 'tools', 'autoStart', 'autoStartWhen', 'nextPhases'] as const;\ntype MigratedField = (typeof MIGRATED_FIELDS)[number];\n\nconst PHASE_DEFAULTS = { exitTool: [null], tools: [null], autoStart: [null], autoStartWhen: [null] } as const;\n\n/**\n * What Factory stored for Work's working phases before they had runners: the seed of #29317, and\n * #29346's for the `nextPhases` it changed. Frozen: a value listed here is one a project can only\n * hold because Factory wrote it, so the migration may replace it.\n */\nconst OLD_WORK_SEED: Readonly<Record<string, Readonly<Record<MigratedField, readonly unknown[]>>>> = {\n triage: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'triage' }],\n nextPhases: [['intake', 'planning', 'done', 'canceled']],\n },\n planning: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n exitTool: [{ id: 'submit_plan', autoApprove: false }],\n nextPhases: [['execute', 'triage', 'intake', 'done', 'canceled']],\n },\n execute: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [['review', 'planning', 'done', 'canceled']],\n },\n review: {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [\n ['execute', 'intake', 'done', 'canceled'],\n ['execute', 'intake', 'pr-review', 'done', 'canceled'],\n ],\n },\n 'pr-review': {\n ...PHASE_DEFAULTS,\n runner: [{ context: 'work' }],\n nextPhases: [\n ['intake', 'done', 'canceled'],\n ['intake', 'planning', 'execute', 'done', 'canceled'],\n ],\n },\n};\n\n/** Building's goal while Work still had its self-review phase. */\nconst SELF_REVIEW_BUILD_OBJECTIVE =\n 'Build the plan approved in Planning for this work item. Done when every step of that plan is implemented on ' +\n \"the work branch; the plan's verification gates (the tests, typecheck and lint it names, else the narrowest \" +\n 'relevant ones) were run on the final head and passed; the branch is pushed; and the card was moved on with ' +\n \"factory_transition_work_item out of Building (to Review or PR review as the builder's hand-off says, or back to \" +\n \"Planning if the plan proved wrong); the builder's latest message names the move and the pushed head. \" +\n OWN_CARD_HAND_OFF +\n ' Continue while any of that is missing. Waiting only when the agent asked a person a question it cannot ' +\n 'answer from the repository.';\n\n/**\n * The Work seed this migration fills from: Work as it was while it had its self-review phase and\n * Triage. Only projects stored before then hold the old defaults it replaces, and their rows still\n * have those phases, so they get their runners (and keep their moves into Triage) rather than\n * today's seed, which has neither.\n */\nexport function workSeedWithSelfReview(): StoredBoardInput {\n const seed = workSeedWithTriage();\n const phases = seed.phases.flatMap((phase): StoredPhaseInput[] => {\n if (phase.key !== 'execute') return [phase];\n const goal = phase.runner?.goal && { ...phase.runner.goal, objective: SELF_REVIEW_BUILD_OBJECTIVE };\n return [\n {\n ...phase,\n runner: { ...phase.runner, ...(goal ? { goal } : {}) },\n nextPhases: ['review', 'pr-review', 'planning', 'done', 'canceled'],\n },\n {\n key: 'review',\n name: 'Review',\n kind: 'working',\n runner: { skill: 'factory-self-review', context: 'review' },\n autoStart: true,\n autoStartWhen: { operator: 'AND', conditions: [{ field: 'item.pullRequest', operator: 'not_exists' }] },\n tools: ['factory_record_review_verdict'],\n nextPhases: ['execute', 'intake', 'pr-review', 'done', 'canceled'],\n },\n ];\n });\n return { ...seed, phases };\n}\n\n/** Stable JSON with sorted keys; an unset field, `null`, `false` and no tools all read the same. */\nfunction canonical(field: MigratedField, value: unknown): string {\n if (value === undefined || value === null || value === false) return 'null';\n if (field === 'tools' && Array.isArray(value) && value.length === 0) return 'null';\n return JSON.stringify(sorted(value));\n}\n\nfunction sorted(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(sorted);\n if (value === null || typeof value !== 'object') return value;\n return Object.fromEntries(\n Object.entries(value)\n .filter(([, entry]) => entry !== undefined)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, entry]) => [key, sorted(entry)]),\n );\n}\n\nfunction toInput({ position: _position, ...phase }: StoredPhaseRecord): StoredPhaseInput {\n return phase;\n}\n\n/** Whether Factory may write the new value over the stored one: the stored one is still an old default. */\nfunction stillOldDefault(phaseKey: string, field: MigratedField, stored: unknown): boolean {\n const old = OLD_WORK_SEED[phaseKey]?.[field] ?? [];\n const current = canonical(field, stored);\n return old.some(value => canonical(field, value) === current);\n}\n\n/**\n * Gives a project's stored Work board the phase runners, goal, automatic starts and phase tools\n * of Factory's Work seed, field by field: only a field that still holds the value Factory\n * stored before is filled, so every field a person edited stays as they left it. A phase the\n * row lacks, or holds as another kind, is left alone, as is a move to a phase the row lacks.\n */\ntype StoredRunner = StoredPhaseInput['runner'];\n\n/**\n * The seed's runner parts a stored runner still lacks or holds at the old default: `context` when\n * it is the old seed's, `skill` and `goal` when unset (the old seed set neither). Instructions and\n * any part a person set stay as they are.\n */\nfunction migrateRunner(\n phaseKey: string,\n stored: StoredRunner,\n target: StoredRunner,\n): { value: NonNullable<StoredRunner>; filled: string[] } | undefined {\n if (!target) return undefined;\n const value: NonNullable<StoredRunner> = { ...(stored ?? {}) };\n const filled: string[] = [];\n const oldContexts = (OLD_WORK_SEED[phaseKey]?.runner ?? []).map(old => (old as { context?: string }).context);\n if (\n target.context !== undefined &&\n value.context !== target.context &&\n (value.context === undefined || oldContexts.includes(value.context))\n ) {\n value.context = target.context;\n filled.push('context');\n }\n if (target.skill !== undefined && value.skill === undefined) {\n value.skill = target.skill;\n filled.push('skill');\n }\n if (target.goal !== undefined && value.goal === undefined) {\n value.goal = target.goal;\n filled.push('goal');\n }\n return filled.length > 0 ? { value, filled } : undefined;\n}\n\nexport function migrateWorkPhaseRunners(\n board: StoredBoardRecord,\n seed = workSeedWithSelfReview(),\n): { board: { name: string; description: string | null; phases: StoredPhaseInput[] }; filled: string[] } | undefined {\n const phaseKeys = new Set(board.phases.map(phase => phase.key));\n const filled: string[] = [];\n const phases = board.phases.map(record => {\n const phase = toInput(record);\n const target = seed.phases.find(candidate => candidate.key === phase.key);\n if (!target || target.kind !== phase.kind || !OLD_WORK_SEED[phase.key]) return phase;\n const next: StoredPhaseInput = { ...phase };\n // The runner is migrated part by part: a person who only wrote instructions (the one part the\n // old seed left editable) still gets the skill, goal and context, and keeps the instructions.\n const runner = migrateRunner(phase.key, phase.runner, target.runner);\n if (runner) {\n next.runner = runner.value;\n filled.push(...runner.filled.map(part => `${phase.key}.runner.${part}`));\n }\n for (const field of MIGRATED_FIELDS) {\n if (field === 'runner') continue;\n const value = target[field] ?? null;\n if (canonical(field, value) === canonical(field, phase[field])) continue;\n if (!stillOldDefault(phase.key, field, phase[field])) continue;\n if (field === 'nextPhases' && !(value as string[]).every(key => phaseKeys.has(key))) continue;\n Object.assign(next, { [field]: value });\n filled.push(`${phase.key}.${field}`);\n }\n const moves = next.nextPhases ?? [...phaseKeys].filter(key => key !== phase.key);\n const revert = (field: MigratedField) => {\n if (!filled.includes(`${phase.key}.${field}`)) return;\n Object.assign(next, { [field]: phase[field] });\n filled.splice(filled.indexOf(`${phase.key}.${field}`), 1);\n };\n // The seed's goal is done only once the card moved on along the seed's moves (Building to PR\n // review, say): a phase whose moves a person narrowed runs the skill without the goal, rather\n // than judging a goal it may never meet.\n const seedMoves = (target.nextPhases ?? []).filter(key => phaseKeys.has(key));\n if (\n filled.includes(`${phase.key}.runner.goal`) &&\n next.runner?.goal &&\n !seedMoves.every(key => moves.includes(key))\n ) {\n const { goal: _goal, ...runner } = next.runner;\n next.runner = runner;\n }\n // Auto-start and Factory tools serve the seed's skill; a phase running another skill keeps its own.\n if (next.runner?.skill !== target.runner?.skill || next.runner?.context !== target.runner?.context) {\n for (const field of ['tools', 'autoStart', 'autoStartWhen'] as const) revert(field);\n }\n if (filled.includes(`${phase.key}.runner.goal`) && !next.runner?.goal) {\n filled.splice(filled.indexOf(`${phase.key}.runner.goal`), 1);\n }\n return next;\n });\n if (filled.length === 0) return undefined;\n return { board: { name: board.name, description: board.description, phases }, filled };\n}\n\nexport const WORK_PHASE_RUNNERS_MIGRATION: StoredBoardMigration = {\n key: 'work-phase-runners-v1',\n boardKey: workBoard.id,\n migrate: board => migrateWorkPhaseRunners(board),\n};\n\n/**\n * The board's review phases as {@link boardFlow} finds them: `pullRequestReview` is the first\n * review-seat phase granting `factory_review_source`; `selfReview` the first other one granting\n * `factory_record_review_verdict` and not `factory_review_source`; `build` the last other working\n * phase that moves into self-review.\n */\nfunction reviewPhases(board: StoredBoardRecord) {\n const grants = (phase: StoredPhaseRecord, tool: FactoryPhaseTool) =>\n phase.kind === 'working' && phase.runner?.context === REVIEW_CONTEXT && (phase.tools ?? []).includes(tool);\n const pullRequestReview = board.phases.find(phase => grants(phase, 'factory_review_source'));\n const selfReview = board.phases.find(\n phase =>\n phase !== pullRequestReview &&\n grants(phase, 'factory_record_review_verdict') &&\n !grants(phase, 'factory_review_source'),\n );\n const build = selfReview\n ? board.phases.findLast(\n phase =>\n phase.kind === 'working' &&\n phase !== pullRequestReview &&\n phase !== selfReview &&\n (phase.nextPhases ?? []).includes(selfReview.key),\n )\n : undefined;\n return { pullRequestReview, selfReview, build };\n}\n\n/**\n * Carries a project's retired self-review switch into its boards: with the switch off, a card went\n * past any board's self-review phase, so the phase goes, with every move into it. A board is left\n * as it is, with a warning, when its code board declares the phase (without it the board would run\n * without its code rules), when cards sit in the phase (removing it would strand them), when its\n * build phase could only reach the pull request review through it, or when it is another phase's\n * only move.\n */\nexport function migrateSelfReviewSwitch(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined {\n if (!context.retiredSettings || context.retiredSettings.selfReviewEnabled) return undefined;\n const { pullRequestReview, selfReview, build } = reviewPhases(board);\n if (!selfReview) return undefined;\n const phase = selfReview.key;\n const keep = (reason: string) => {\n context.warn(\n `Board \"${board.key}\" keeps its self-review phase \"${phase}\": ${reason}. The project's self-review ` +\n 'setting was off; remove the phase to keep skipping self-review.',\n );\n return undefined;\n };\n if (context.codePhases(board.key)?.has(phase)) return keep('its code declares it, so remove it in code first');\n // Without the cards it could strand some in the phase: the project's next load runs it again.\n if (!context.occupiedPhases) throw new Error(\"the project's cards can't be read yet\");\n if (context.occupiedPhases.get(board.key)?.has(phase)) return keep('cards sit in it, move them first');\n if (build && !(pullRequestReview && (build.nextPhases ?? []).includes(pullRequestReview.key))) {\n return keep(`\"${build.key}\" can't move to a pull request review without it, add that move first`);\n }\n const stranded = board.phases.find(\n record => record.key !== phase && record.nextPhases?.length && record.nextPhases.every(key => key === phase),\n );\n if (stranded) return keep(`it is the only move out of \"${stranded.key}\", give that phase another move first`);\n const phases = board.phases\n .filter(record => record.key !== phase)\n .map(record => {\n const next = toInput(record);\n if (next.nextPhases) next.nextPhases = next.nextPhases.filter(key => key !== phase);\n return next;\n });\n return { board: { name: board.name, description: board.description, phases }, filled: [`${phase} removed`] };\n}\n\n/**\n * Carries a project's retired auto-run switch into its boards: with it on, every run started\n * without a person, so every working phase starts on its own, for every card (`autoStartWhen`\n * cleared). With it off a run started on its own only where the phase said so, as it does now.\n */\nexport function migrateAutoRunSwitch(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined {\n if (!context.retiredSettings?.autoRunEnabled) return undefined;\n const filled: string[] = [];\n const phases = board.phases.map(record => {\n const phase = toInput(record);\n if (phase.kind !== 'working' || (phase.autoStart && !phase.autoStartWhen)) return phase;\n filled.push(`${phase.key}.autoStart`);\n return { ...phase, autoStart: true, autoStartWhen: null };\n });\n if (filled.length === 0) return undefined;\n return { board: { name: board.name, description: board.description, phases }, filled };\n}\n\nexport const SELF_REVIEW_MIGRATION: StoredBoardMigration = {\n key: 'self-review-switch-v1',\n boardKey: null,\n migrate: migrateSelfReviewSwitch,\n};\n\nexport const AUTO_RUN_MIGRATION: StoredBoardMigration = {\n key: 'auto-run-switch-v1',\n boardKey: null,\n migrate: migrateAutoRunSwitch,\n};\n\n/** The board migrations each project gets once, in order. */\nexport const BOARD_MIGRATIONS: readonly StoredBoardMigration[] = [\n WORK_PHASE_RUNNERS_MIGRATION,\n SELF_REVIEW_MIGRATION,\n AUTO_RUN_MIGRATION,\n];\n"],"mappings":";;;;AAaA,MAAM,kBAAkB;CAAC;CAAU;CAAY;CAAS;CAAa;CAAiB;AAAY;AAGlG,MAAM,iBAAiB;CAAE,UAAU,CAAC,IAAI;CAAG,OAAO,CAAC,IAAI;CAAG,WAAW,CAAC,IAAI;CAA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D,IAAI,OAAO,WAAW,GAAG,OAAO,KAAA;CAChC,OAAO;EAAE,OAAO;GAAE,MAAM,MAAM;GAAM,aAAa,MAAM;GAAa;EAAO;EAAG;CAAO;AACvF;AAEA,MAAa,wBAA8C;CACzD,KAAK;CACL,UAAU;CACV,SAAS;AACX;AAEA,MAAa,qBAA2C;CACtD,KAAK;CACL,UAAU;CACV,SAAS;AACX;;AAGA,MAAa,mBAAoD;CAC/D;CACA;CACA;AACF"}
@@ -0,0 +1,9 @@
1
+ import type { StoredBoardInput } from '../storage/domains/boards/base.js';
2
+ /**
3
+ * Work as Factory stored it before new projects' Work dropped Triage: today's Work plus its
4
+ * Triage phase and the moves into it. A project that existed before then, and so has no stored
5
+ * Work row only because it never loaded on a release that stores boards, is given this one, so
6
+ * an upgrade never changes the phases a project's cards can sit in. Reset gives it back too.
7
+ */
8
+ export declare function workSeedWithTriage(): StoredBoardInput;
9
+ //# sourceMappingURL=work-seeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-seeds.d.ts","sourceRoot":"","sources":["../../src/boards/work-seeds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,mCAAmC,CAAC;AAoB5F;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,gBAAgB,CAUrD"}
@@ -0,0 +1,56 @@
1
+ import { boardDefinitionOf } from "./stored-board.js";
2
+ import { workBoard } from "./work.js";
3
+ // src/boards/work-seeds.ts
4
+ /** The Triage phase Work had before new projects' Work dropped it. */
5
+ const TRIAGE_PHASE = {
6
+ key: "triage",
7
+ name: "Triage",
8
+ kind: "working",
9
+ runner: {
10
+ skill: "factory-triage",
11
+ context: "triage"
12
+ },
13
+ nextPhases: [
14
+ "intake",
15
+ "planning",
16
+ "done",
17
+ "canceled"
18
+ ]
19
+ };
20
+ /** The moves into Triage each phase had, at the place they had them. */
21
+ const MOVES_INTO_TRIAGE = {
22
+ intake: { after: null },
23
+ planning: { after: "execute" }
24
+ };
25
+ /**
26
+ * Work as Factory stored it before new projects' Work dropped Triage: today's Work plus its
27
+ * Triage phase and the moves into it. A project that existed before then, and so has no stored
28
+ * Work row only because it never loaded on a release that stores boards, is given this one, so
29
+ * an upgrade never changes the phases a project's cards can sit in. Reset gives it back too.
30
+ */
31
+ function workSeedWithTriage() {
32
+ const seed = boardDefinitionOf(workBoard);
33
+ const phases = seed.phases.flatMap((phase) => {
34
+ const into = MOVES_INTO_TRIAGE[phase.key];
35
+ const withMove = into ? {
36
+ ...phase,
37
+ nextPhases: withTriage(phase.nextPhases ?? [], into.after)
38
+ } : phase;
39
+ return phase.key === "intake" ? [withMove, TRIAGE_PHASE] : [withMove];
40
+ });
41
+ return {
42
+ ...seed,
43
+ phases
44
+ };
45
+ }
46
+ function withTriage(nextPhases, after) {
47
+ const index = after === null ? 0 : nextPhases.indexOf(after) + 1;
48
+ return [
49
+ ...nextPhases.slice(0, index),
50
+ "triage",
51
+ ...nextPhases.slice(index)
52
+ ];
53
+ }
54
+ export { workSeedWithTriage };
55
+
56
+ //# sourceMappingURL=work-seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-seeds.js","names":[],"sources":["../../src/boards/work-seeds.ts"],"sourcesContent":["import type { StoredBoardInput, StoredPhaseInput } from '../storage/domains/boards/base.js';\nimport { boardDefinitionOf } from './stored-board.js';\nimport { workBoard } from './work.js';\n\n/** The Triage phase Work had before new projects' Work dropped it. */\nconst TRIAGE_PHASE: StoredPhaseInput = {\n key: 'triage',\n name: 'Triage',\n kind: 'working',\n runner: { skill: 'factory-triage', context: 'triage' },\n // A confirmed bug goes to Planning; any other open issue waits in Intake for a person.\n nextPhases: ['intake', 'planning', 'done', 'canceled'],\n};\n\n/** The moves into Triage each phase had, at the place they had them. */\nconst MOVES_INTO_TRIAGE: Readonly<Record<string, { after: string | null }>> = {\n intake: { after: null },\n planning: { after: 'execute' },\n};\n\n/**\n * Work as Factory stored it before new projects' Work dropped Triage: today's Work plus its\n * Triage phase and the moves into it. A project that existed before then, and so has no stored\n * Work row only because it never loaded on a release that stores boards, is given this one, so\n * an upgrade never changes the phases a project's cards can sit in. Reset gives it back too.\n */\nexport function workSeedWithTriage(): StoredBoardInput {\n const seed = boardDefinitionOf(workBoard);\n const phases = seed.phases.flatMap((phase): StoredPhaseInput[] => {\n const into = MOVES_INTO_TRIAGE[phase.key];\n const withMove: StoredPhaseInput = into\n ? { ...phase, nextPhases: withTriage(phase.nextPhases ?? [], into.after) }\n : phase;\n return phase.key === 'intake' ? [withMove, TRIAGE_PHASE] : [withMove];\n });\n return { ...seed, phases };\n}\n\nfunction withTriage(nextPhases: readonly string[], after: string | null): string[] {\n const index = after === null ? 0 : nextPhases.indexOf(after) + 1;\n return [...nextPhases.slice(0, index), 'triage', ...nextPhases.slice(index)];\n}\n"],"mappings":";;;;AAKA,MAAM,eAAiC;CACrC,KAAK;CACL,MAAM;CACN,MAAM;CACN,QAAQ;EAAE,OAAO;EAAkB,SAAS;CAAS;CAErD,YAAY;EAAC;EAAU;EAAY;EAAQ;CAAU;AACvD;;AAGA,MAAM,oBAAwE;CAC5E,QAAQ,EAAE,OAAO,KAAK;CACtB,UAAU,EAAE,OAAO,UAAU;AAC/B;;;;;;;AAQA,SAAgB,qBAAuC;CACrD,MAAM,OAAO,kBAAkB,SAAS;CACxC,MAAM,SAAS,KAAK,OAAO,SAAS,UAA8B;EAChE,MAAM,OAAO,kBAAkB,MAAM;EACrC,MAAM,WAA6B,OAC/B;GAAE,GAAG;GAAO,YAAY,WAAW,MAAM,cAAc,CAAC,GAAG,KAAK,KAAK;EAAE,IACvE;EACJ,OAAO,MAAM,QAAQ,WAAW,CAAC,UAAU,YAAY,IAAI,CAAC,QAAQ;CACtE,CAAC;CACD,OAAO;EAAE,GAAG;EAAM;CAAO;AAC3B;AAEA,SAAS,WAAW,YAA+B,OAAgC;CACjF,MAAM,QAAQ,UAAU,OAAO,IAAI,WAAW,QAAQ,KAAK,IAAI;CAC/D,OAAO;EAAC,GAAG,WAAW,MAAM,GAAG,KAAK;EAAG;EAAU,GAAG,WAAW,MAAM,KAAK;CAAC;AAC7E"}
@@ -8,6 +8,6 @@ export declare const OWN_CARD_HAND_OFF: string;
8
8
  * spells out when the build is done and when it waits for a person.
9
9
  */
10
10
  export declare const BUILD_OBJECTIVE: string;
11
- export type WorkBoardPhase = 'intake' | 'triage' | 'planning' | 'execute' | 'pr-review' | 'done' | 'canceled';
12
- export declare const workBoard: import("./define-board.js").BoardDefinition<"work", "canceled" | "done" | "execute" | "intake" | "planning" | "pr-review" | "triage">;
11
+ export type WorkBoardPhase = 'intake' | 'planning' | 'execute' | 'pr-review' | 'done' | 'canceled';
12
+ export declare const workBoard: import("./define-board.js").BoardDefinition<"work", "canceled" | "done" | "execute" | "intake" | "planning" | "pr-review">;
13
13
  //# sourceMappingURL=work.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"work.d.ts","sourceRoot":"","sources":["../../src/boards/work.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAE4E,CAAC;AAE3G;;;GAGG;AACH,eAAO,MAAM,eAAe,QAQG,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,UAAU,CAAC;AAE9G,eAAO,MAAM,SAAS,uIAgEpB,CAAC"}
1
+ {"version":3,"file":"work.d.ts","sourceRoot":"","sources":["../../src/boards/work.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAE4E,CAAC;AAE3G;;;GAGG;AACH,eAAO,MAAM,eAAe,QAQG,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,UAAU,CAAC;AAEnG,eAAO,MAAM,SAAS,4HA0DpB,CAAC"}
@@ -24,27 +24,12 @@ const workBoard = compileBoardDefinition({
24
24
  name: "Intake",
25
25
  kind: "resting",
26
26
  nextPhases: [
27
- "triage",
28
27
  "planning",
29
28
  "pr-review",
30
29
  "done",
31
30
  "canceled"
32
31
  ]
33
32
  },
34
- triage: {
35
- name: "Triage",
36
- kind: "working",
37
- runner: {
38
- skill: "factory-triage",
39
- context: "triage"
40
- },
41
- nextPhases: [
42
- "intake",
43
- "planning",
44
- "done",
45
- "canceled"
46
- ]
47
- },
48
33
  planning: {
49
34
  name: "Planning",
50
35
  kind: "working",
@@ -54,7 +39,6 @@ const workBoard = compileBoardDefinition({
54
39
  },
55
40
  nextPhases: [
56
41
  "execute",
57
- "triage",
58
42
  "intake",
59
43
  "done",
60
44
  "canceled"
@@ -1 +1 @@
1
- {"version":3,"file":"work.js","names":[],"sources":["../../src/boards/work.ts"],"sourcesContent":["import { DEFAULT_BOARD_ID } from './default-board.js';\nimport { compileBoardDefinition } from './define-board.js';\nimport type { BoardPhaseDefinition } from './define-board.js';\n\n/**\n * A change request tracked on its own card never attaches to this one, so Review refuses the card and\n * the builder leaves it in Building: the goal counts that hand-off as done rather than looping on it.\n */\nexport const OWN_CARD_HAND_OFF =\n 'Also done, with the card left in Building, when the change request was opened but is tracked on its own card ' +\n \"and the builder's latest message posts its link and says a person should confirm it is reviewed there.\";\n\n/**\n * The goal Building pursues. The goal judge sees only this text and the latest messages, so it\n * spells out when the build is done and when it waits for a person.\n */\nexport const BUILD_OBJECTIVE =\n 'Build the plan approved in Planning for this work item. Done when every step of that plan is implemented on ' +\n \"the work branch; the plan's verification gates (the tests, typecheck and lint it names, else the narrowest \" +\n 'relevant ones) were run on the final head and passed; the branch is pushed; and the card was moved on with ' +\n 'factory_transition_work_item out of Building (to Review after opening the change request, or back to ' +\n \"Planning if the plan proved wrong); the builder's latest message names the move and the pushed head. \" +\n OWN_CARD_HAND_OFF +\n ' Continue while any of that is missing. Waiting only when the agent asked a person a question it cannot ' +\n 'answer from the repository.';\n\nexport type WorkBoardPhase = 'intake' | 'triage' | 'planning' | 'execute' | 'pr-review' | 'done' | 'canceled';\n\nexport const workBoard = compileBoardDefinition<'work', Record<WorkBoardPhase, BoardPhaseDefinition<WorkBoardPhase>>>({\n id: DEFAULT_BOARD_ID,\n name: 'Work',\n initialPhase: 'intake',\n sourceClosed: { completed: 'done', canceled: 'canceled' },\n phases: {\n intake: {\n name: 'Intake',\n kind: 'resting',\n // Never straight to Building: a plan comes first. Review takes a pull request's own card;\n // Done is where a completed source closes it.\n nextPhases: ['triage', 'planning', 'pr-review', 'done', 'canceled'],\n },\n triage: {\n name: 'Triage',\n kind: 'working',\n runner: { skill: 'factory-triage', context: 'triage' },\n // A confirmed bug goes to Planning; any other open issue waits in Intake for a person.\n nextPhases: ['intake', 'planning', 'done', 'canceled'],\n },\n planning: {\n name: 'Planning',\n kind: 'working',\n // Planning and Building share one session, so the builder keeps the plan's context.\n runner: { skill: 'factory-plan', context: 'work' },\n nextPhases: ['execute', 'triage', 'intake', 'done', 'canceled'],\n // The card stays in Planning until submit_plan comes back approved; then factory-plan moves it.\n exitTool: { id: 'submit_plan', autoApprove: false },\n },\n execute: {\n name: 'Building',\n kind: 'working',\n runner: { skill: 'factory-build', context: 'work', goal: { objective: BUILD_OBJECTIVE, maxRuns: 20 } },\n // Review once the builder opened the change request; Planning again when the build shows\n // the plan was wrong.\n nextPhases: ['pr-review', 'planning', 'done', 'canceled'],\n },\n 'pr-review': {\n // Keyed `pr-review`: projects stored before Work dropped its self-review phase hold a\n // `review` phase for it, and the retired Review board's cards read as `pr-review`.\n name: 'Review',\n // A card's pull request is reviewed here by the independent reviewer, in its own\n // review seat on the pull request's branch. Work has no self-review phase; a board that\n // wants one adds a review-context phase granting only factory_record_review_verdict.\n kind: 'working',\n runner: { skill: 'factory-review', context: 'review' },\n tools: ['factory_record_review_verdict', 'factory_review_source'],\n // Merged, closed, or set aside in Intake. An issue card can go back to its builder for a\n // fix; a pull request's own card never reaches the builder's lanes (workPullRequestCardRejection).\n nextPhases: ['intake', 'planning', 'execute', 'done', 'canceled'],\n },\n done: {\n name: 'Done',\n kind: 'terminal',\n // A review request on a finished pull request reopens its review.\n nextPhases: ['pr-review'],\n },\n canceled: {\n name: 'Canceled',\n kind: 'terminal',\n // Revived into Intake; a pull request closed without merging and then reopened goes back to Review.\n nextPhases: ['intake', 'pr-review'],\n },\n },\n});\n"],"mappings":";;;;;;;AAQA,MAAa,oBACX;;;;;AAOF,MAAa,kBACX;AAWF,MAAa,YAAY,uBAA6F;CACpH,IAAI;CACJ,MAAM;CACN,cAAc;CACd,cAAc;EAAE,WAAW;EAAQ,UAAU;CAAW;CACxD,QAAQ;EACN,QAAQ;GACN,MAAM;GACN,MAAM;GAGN,YAAY;IAAC;IAAU;IAAY;IAAa;IAAQ;GAAU;EACpE;EACA,QAAQ;GACN,MAAM;GACN,MAAM;GACN,QAAQ;IAAE,OAAO;IAAkB,SAAS;GAAS;GAErD,YAAY;IAAC;IAAU;IAAY;IAAQ;GAAU;EACvD;EACA,UAAU;GACR,MAAM;GACN,MAAM;GAEN,QAAQ;IAAE,OAAO;IAAgB,SAAS;GAAO;GACjD,YAAY;IAAC;IAAW;IAAU;IAAU;IAAQ;GAAU;GAE9D,UAAU;IAAE,IAAI;IAAe,aAAa;GAAM;EACpD;EACA,SAAS;GACP,MAAM;GACN,MAAM;GACN,QAAQ;IAAE,OAAO;IAAiB,SAAS;IAAQ,MAAM;KAAE,WAAW;KAAiB,SAAS;IAAG;GAAE;GAGrG,YAAY;IAAC;IAAa;IAAY;IAAQ;GAAU;EAC1D;EACA,aAAa;GAGX,MAAM;GAIN,MAAM;GACN,QAAQ;IAAE,OAAO;IAAkB,SAAS;GAAS;GACrD,OAAO,CAAC,iCAAiC,uBAAuB;GAGhE,YAAY;IAAC;IAAU;IAAY;IAAW;IAAQ;GAAU;EAClE;EACA,MAAM;GACJ,MAAM;GACN,MAAM;GAEN,YAAY,CAAC,WAAW;EAC1B;EACA,UAAU;GACR,MAAM;GACN,MAAM;GAEN,YAAY,CAAC,UAAU,WAAW;EACpC;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"work.js","names":[],"sources":["../../src/boards/work.ts"],"sourcesContent":["import { DEFAULT_BOARD_ID } from './default-board.js';\nimport { compileBoardDefinition } from './define-board.js';\nimport type { BoardPhaseDefinition } from './define-board.js';\n\n/**\n * A change request tracked on its own card never attaches to this one, so Review refuses the card and\n * the builder leaves it in Building: the goal counts that hand-off as done rather than looping on it.\n */\nexport const OWN_CARD_HAND_OFF =\n 'Also done, with the card left in Building, when the change request was opened but is tracked on its own card ' +\n \"and the builder's latest message posts its link and says a person should confirm it is reviewed there.\";\n\n/**\n * The goal Building pursues. The goal judge sees only this text and the latest messages, so it\n * spells out when the build is done and when it waits for a person.\n */\nexport const BUILD_OBJECTIVE =\n 'Build the plan approved in Planning for this work item. Done when every step of that plan is implemented on ' +\n \"the work branch; the plan's verification gates (the tests, typecheck and lint it names, else the narrowest \" +\n 'relevant ones) were run on the final head and passed; the branch is pushed; and the card was moved on with ' +\n 'factory_transition_work_item out of Building (to Review after opening the change request, or back to ' +\n \"Planning if the plan proved wrong); the builder's latest message names the move and the pushed head. \" +\n OWN_CARD_HAND_OFF +\n ' Continue while any of that is missing. Waiting only when the agent asked a person a question it cannot ' +\n 'answer from the repository.';\n\nexport type WorkBoardPhase = 'intake' | 'planning' | 'execute' | 'pr-review' | 'done' | 'canceled';\n\nexport const workBoard = compileBoardDefinition<'work', Record<WorkBoardPhase, BoardPhaseDefinition<WorkBoardPhase>>>({\n id: DEFAULT_BOARD_ID,\n name: 'Work',\n initialPhase: 'intake',\n sourceClosed: { completed: 'done', canceled: 'canceled' },\n phases: {\n intake: {\n name: 'Intake',\n kind: 'resting',\n // Never straight to Building: a plan comes first. Review takes a pull request's own card;\n // Done is where a completed source closes it. New projects' Work has no Triage; projects\n // stored before keep theirs (workSeedWithTriage).\n nextPhases: ['planning', 'pr-review', 'done', 'canceled'],\n },\n planning: {\n name: 'Planning',\n kind: 'working',\n // Planning and Building share one session, so the builder keeps the plan's context.\n runner: { skill: 'factory-plan', context: 'work' },\n nextPhases: ['execute', 'intake', 'done', 'canceled'],\n // The card stays in Planning until submit_plan comes back approved; then factory-plan moves it.\n exitTool: { id: 'submit_plan', autoApprove: false },\n },\n execute: {\n name: 'Building',\n kind: 'working',\n runner: { skill: 'factory-build', context: 'work', goal: { objective: BUILD_OBJECTIVE, maxRuns: 20 } },\n // Review once the builder opened the change request; Planning again when the build shows\n // the plan was wrong.\n nextPhases: ['pr-review', 'planning', 'done', 'canceled'],\n },\n 'pr-review': {\n // Keyed `pr-review`: projects stored before Work dropped its self-review phase hold a\n // `review` phase for it, and the retired Review board's cards read as `pr-review`.\n name: 'Review',\n // A card's pull request is reviewed here by the independent reviewer, in its own\n // review seat on the pull request's branch. Work has no self-review phase; a board that\n // wants one adds a review-context phase granting only factory_record_review_verdict.\n kind: 'working',\n runner: { skill: 'factory-review', context: 'review' },\n tools: ['factory_record_review_verdict', 'factory_review_source'],\n // Merged, closed, or set aside in Intake. An issue card can go back to its builder for a\n // fix; a pull request's own card never reaches the builder's lanes (workPullRequestCardRejection).\n nextPhases: ['intake', 'planning', 'execute', 'done', 'canceled'],\n },\n done: {\n name: 'Done',\n kind: 'terminal',\n // A review request on a finished pull request reopens its review.\n nextPhases: ['pr-review'],\n },\n canceled: {\n name: 'Canceled',\n kind: 'terminal',\n // Revived into Intake; a pull request closed without merging and then reopened goes back to Review.\n nextPhases: ['intake', 'pr-review'],\n },\n },\n});\n"],"mappings":";;;;;;;AAQA,MAAa,oBACX;;;;;AAOF,MAAa,kBACX;AAWF,MAAa,YAAY,uBAA6F;CACpH,IAAI;CACJ,MAAM;CACN,cAAc;CACd,cAAc;EAAE,WAAW;EAAQ,UAAU;CAAW;CACxD,QAAQ;EACN,QAAQ;GACN,MAAM;GACN,MAAM;GAIN,YAAY;IAAC;IAAY;IAAa;IAAQ;GAAU;EAC1D;EACA,UAAU;GACR,MAAM;GACN,MAAM;GAEN,QAAQ;IAAE,OAAO;IAAgB,SAAS;GAAO;GACjD,YAAY;IAAC;IAAW;IAAU;IAAQ;GAAU;GAEpD,UAAU;IAAE,IAAI;IAAe,aAAa;GAAM;EACpD;EACA,SAAS;GACP,MAAM;GACN,MAAM;GACN,QAAQ;IAAE,OAAO;IAAiB,SAAS;IAAQ,MAAM;KAAE,WAAW;KAAiB,SAAS;IAAG;GAAE;GAGrG,YAAY;IAAC;IAAa;IAAY;IAAQ;GAAU;EAC1D;EACA,aAAa;GAGX,MAAM;GAIN,MAAM;GACN,QAAQ;IAAE,OAAO;IAAkB,SAAS;GAAS;GACrD,OAAO,CAAC,iCAAiC,uBAAuB;GAGhE,YAAY;IAAC;IAAU;IAAY;IAAW;IAAQ;GAAU;EAClE;EACA,MAAM;GACJ,MAAM;GACN,MAAM;GAEN,YAAY,CAAC,WAAW;EAC1B;EACA,UAAU;GACR,MAAM;GACN,MAAM;GAEN,YAAY,CAAC,UAAU,WAAW;EACpC;CACF;AACF,CAAC"}
package/dist/factory.d.ts CHANGED
@@ -216,8 +216,9 @@ export interface MastraFactoryConfig {
216
216
  */
217
217
  skills?: readonly InlineSkill[];
218
218
  /**
219
- * Whether projects get the built-in Work board, stored in each project once, and the legacy
220
- * read-only Review board. Default: true.
219
+ * @deprecated Ignored, and removed in a future release. Every project gets Factory's Work board
220
+ * when it has no boards yet; one that has any keeps what it has. To run your own Work board,
221
+ * store it under the `work` key with `factory.upsertBoard(board, { projects: 'all' })`.
221
222
  */
222
223
  includeDefaultBoards?: boolean;
223
224
  /**
@@ -266,8 +267,11 @@ export declare class MastraFactory {
266
267
  /**
267
268
  * Writes a board definition into projects: each project that has no board under its key gets
268
269
  * it, and each one that has it, edited or not, has it replaced at the next revision. Use it to
269
- * push a board from code into projects; it isn't run for you, and projects created later don't
270
- * get it until you run it again. A Work or app board's key keeps that board's code behaviour,
270
+ * push a board from code into projects, at startup. With `projects: 'all'`, a project that has
271
+ * no boards yet on its first load (one created later, during onboarding) gets it too, before
272
+ * Factory's own boards; Factory adds its default Work only to a project with no boards, so that
273
+ * project gets none. This lasts for the process, so run it at every startup. A Work or app
274
+ * board's key keeps that board's code behaviour,
271
275
  * so the definition is checked as an edit is; a new key gets none (no tool, source-closed or
272
276
  * event rules). The board is validated once, as the boards API does, and each write is audited
273
277
  * as `factory.board.created` or `factory.board.updated` by `system:factory`. Refusals throw a
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,OAAO,KAAK,EAAiC,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAkB,yBAAyB,EAAoB,MAAM,wBAAwB,CAAC;AAqB1G,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOvE,OAAO,KAAK,EAAE,kBAAkB,EAA8B,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAmBlF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAiCxD,OAAO,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