@mastra/factory 0.29.0-alpha.7 → 0.29.0-alpha.8
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.
- package/README.md +50 -20
- package/dist/boards/board-events.d.ts +23 -0
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +37 -3
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts +6 -4
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +9 -6
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/intake-routing.d.ts +30 -16
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +41 -28
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/project-boards.d.ts +15 -0
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +43 -7
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/factory.d.ts +4 -14
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +22 -15
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +101 -0
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +7 -3
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +7 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +15 -1
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +1 -1
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +2 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.d.ts +1 -0
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.js +4 -1
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
- package/dist/integrations/slack/run-error-card.js +6 -1
- package/dist/integrations/slack/run-error-card.js.map +1 -1
- package/dist/links.d.ts +4 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +5 -3
- package/dist/links.js.map +1 -1
- package/dist/routes/boards.d.ts +1 -1
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +32 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +36 -9
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake-check.d.ts.map +1 -1
- package/dist/routes/intake-check.js +3 -1
- package/dist/routes/intake-check.js.map +1 -1
- package/dist/routes/intake-routes.d.ts +0 -3
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +1 -1
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/skills.d.ts +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +92 -28
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/surface.d.ts +0 -3
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +0 -1
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts +6 -0
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +10 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +74 -32
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +3 -2
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +5 -3
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/public-failure-reason.d.ts +11 -0
- package/dist/rules/public-failure-reason.d.ts.map +1 -0
- package/dist/rules/public-failure-reason.js +136 -0
- package/dist/rules/public-failure-reason.js.map +1 -0
- package/dist/rules/transition-service.d.ts +13 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +5 -1
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +12 -0
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +11 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/run-error.d.ts +1 -1
- package/dist/run-error.d.ts.map +1 -1
- package/dist/run-error.js +21 -12
- package/dist/run-error.js.map +1 -1
- package/dist/session/environment-state-processor.d.ts.map +1 -1
- package/dist/session/environment-state-processor.js +6 -2
- package/dist/session/environment-state-processor.js.map +1 -1
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +5 -3
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/skills/app-skills.d.ts +3 -2
- package/dist/skills/app-skills.d.ts.map +1 -1
- package/dist/skills/app-skills.js +5 -3
- package/dist/skills/app-skills.js.map +1 -1
- package/dist/skills/catalog.d.ts +23 -4
- package/dist/skills/catalog.d.ts.map +1 -1
- package/dist/skills/catalog.js +61 -28
- package/dist/skills/catalog.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +6 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +12 -0
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +3 -0
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +4 -0
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/skill-overrides/base.d.ts +28 -4
- package/dist/storage/domains/skill-overrides/base.d.ts.map +1 -1
- package/dist/storage/domains/skill-overrides/base.js +54 -1
- package/dist/storage/domains/skill-overrides/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +13 -5
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +1 -1
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +0 -1
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +0 -3
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +2 -1
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/workspace.d.ts +5 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +69 -9
- package/dist/workspace.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated', 'routed_again'],\n intake_order: ['updated', 'evaluator_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['updated', 'reverted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered', 'rerouted'],\n sandbox_env: ['set', 'updated', 'deleted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EAAC;EAAW;EAAW;EAAW;EAAe;EAAuB;CAAmB;CACtG,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;EAAuB;CAAc;CACnF,cAAc,CAAC,WAAW,mBAAmB;CAC7C,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;EAAW;CAAO;CAChD,OAAO
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated', 'routed_again'],\n intake_order: ['updated', 'evaluator_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['created', 'updated', 'reverted', 'deleted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered', 'rerouted'],\n sandbox_env: ['set', 'updated', 'deleted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MA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Input {
|
|
|
140
140
|
on?: RouteEvent[];
|
|
141
141
|
/** Writes the route as 0.28 did, moving cards on `pull_request.opened` and filing none: how a deleted one is restored. */
|
|
142
142
|
pullRequestOpenedMovesOnly?: true;
|
|
143
|
+
/**
|
|
144
|
+
* Writes the route as one stored before rules decided outsiders' pull requests, whose card moves
|
|
145
|
+
* skip an outside author's pull request: how a deleted one is restored. `false` lets them match
|
|
146
|
+
* (what every new route gets); on an update, only an explicit `false` clears the gate.
|
|
147
|
+
*/
|
|
148
|
+
outsiderPullRequestsGated?: boolean;
|
|
143
149
|
}
|
|
144
150
|
export interface StoredIntakeRouteRecord {
|
|
145
151
|
id: string;
|
|
@@ -161,6 +167,12 @@ export interface StoredIntakeRouteRecord {
|
|
|
161
167
|
* names that event and only moves cards on it, as it always has. Writing `on` again clears it.
|
|
162
168
|
*/
|
|
163
169
|
pullRequestOpenedMovesOnly?: true;
|
|
170
|
+
/**
|
|
171
|
+
* Set on a route stored before rules decided outsiders' pull requests: its card moves skip an
|
|
172
|
+
* outside author's pull request unless its `when` tests `pullRequest.trusted`, as they always
|
|
173
|
+
* have. Edits never change it; only an explicit `outsiderPullRequestsGated: false` patch clears it.
|
|
174
|
+
*/
|
|
175
|
+
outsiderPullRequestsGated?: true;
|
|
164
176
|
revision: number;
|
|
165
177
|
createdBy: string;
|
|
166
178
|
createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/base.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAQxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8B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AC5G,wBAAsB,eAAe,CACnC,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,gBAAgB,EACvB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAKnC;AAiMD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS1G"}
|
|
@@ -672,6 +672,7 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
672
672
|
...patch.name !== void 0 && { name: patch.name },
|
|
673
673
|
...patch.enabled !== void 0 && { enabled: patch.enabled },
|
|
674
674
|
...patch.when !== void 0 && { when_condition: patch.when },
|
|
675
|
+
...patch.outsiderPullRequestsGated === false && { outsider_pull_requests_gated: false },
|
|
675
676
|
...patch.target !== void 0 && {
|
|
676
677
|
board_key: patch.target.boardKey,
|
|
677
678
|
phase_key: patch.target.phaseKey ?? null,
|
|
@@ -983,6 +984,7 @@ function toIntakeRouteRecord(row) {
|
|
|
983
984
|
},
|
|
984
985
|
on: routeEvents(row),
|
|
985
986
|
...routeArrivals(row).pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true },
|
|
987
|
+
...row.outsider_pull_requests_gated !== false && { outsiderPullRequestsGated: true },
|
|
986
988
|
revision: row.revision,
|
|
987
989
|
createdBy: row.created_by,
|
|
988
990
|
createdAt: row.created_at,
|
|
@@ -1089,6 +1091,7 @@ async function insertIntakeRoute(ops, scope, route) {
|
|
|
1089
1091
|
on_events: route.input.on ?? null,
|
|
1090
1092
|
join_closed_issue: route.input.target.joinClosedIssue ?? false,
|
|
1091
1093
|
opened_files_pull_requests: route.input.pullRequestOpenedMovesOnly ? null : true,
|
|
1094
|
+
outsider_pull_requests_gated: route.input.outsiderPullRequestsGated === true,
|
|
1092
1095
|
move_to_board_key: route.input.target.moveToBoardKey ?? null,
|
|
1093
1096
|
revision: 1,
|
|
1094
1097
|
created_by: route.actor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { isDeepStrictEqual } from 'node:util';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport { arrivalKinds, DEFAULT_ROUTE_EVENTS, routeEventsProblem } from '../../../boards/board-events.js';\nimport type { ArrivalKind, RouteArrivals, RouteEvent } from '../../../boards/board-events.js';\nimport type { FactoryPhaseTool } from '../../../boards/define-board.js';\nimport { deriveIntakeOrder, kindsTakenWhole, reconcileIntakeOrder } from '../../../boards/intake-order.js';\nimport {\n DEFAULT_INTAKE_ROUTES,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n RETIRED_JOIN_ROUTE,\n} from '../../../boards/work-routes.js';\nimport { currentRuleGroup } from '../../../rules/rule-group.js';\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport type { RetiredAutomationSettings } from '../projects/base.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n /** The objective the phase's runs pursue as a goal. */\n goal?: { objective: string; maxRuns?: number };\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n /** Factory tools the phase grants the session working the card there. */\n tools?: FactoryPhaseTool[] | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\n/** What a board migration may know about the project besides the board it rewrites. */\nexport interface BoardMigrationContext {\n /** The project switches the boards replaced, as the project last stored them; null when unknown. */\n readonly retiredSettings: RetiredAutomationSettings | null;\n /** The phases of each board that cards sit in, by board key; null when the cards can't be read. */\n readonly occupiedPhases: ReadonlyMap<string, ReadonlySet<string>> | null;\n /**\n * The phases the code board under this key declares; undefined for a board only the project\n * stores. A row that drops one runs without its code rules (`mergeCodeBehaviour`).\n */\n codePhases(boardKey: string): ReadonlySet<string> | undefined;\n /** Tells the operator about a board a migration left as it is. */\n warn(message: string): void;\n}\n\n/** A one-time rewrite of a stored board, keyed so each project gets it once. */\nexport interface StoredBoardMigration {\n key: string;\n /** The board it rewrites; `null` rewrites every board the project stores. */\n boardKey: string | null;\n /** The board to write instead, with what changed; undefined leaves it as it is. */\n migrate(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n ): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined;\n}\n\nconst EMPTY_MIGRATION_CONTEXT: BoardMigrationContext = {\n retiredSettings: null,\n occupiedPhases: new Map(),\n codePhases: () => undefined,\n warn: () => {},\n};\n\nexport interface AppliedBoardMigration {\n key: string;\n boardKey: string;\n filled: string[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport interface IntakeRouteTarget {\n boardKey: string;\n /**\n * Unset lands the card in the board's first phase. On a route that joins a closed issue's\n * card, the phase that card moves to when its board allows it; unset leaves it where it is.\n */\n phaseKey?: string | null;\n /**\n * Files a pull request on the card of the issue it closes, which must be on `boardKey`, as one\n * more source instead of a card of its own. The route doesn't match any other arrival.\n */\n joinClosedIssue?: boolean;\n /**\n * On a route moving existing cards (one naming events besides `work_item.opened`), the board the\n * card moves to, at `phaseKey`. `boardKey` stays the board whose cards the route moves. Unset\n * keeps the card on `boardKey`.\n */\n moveToBoardKey?: string | null;\n}\n\n/** An intake route as it is written. */\nexport interface StoredIntakeRouteInput {\n name: string;\n enabled?: boolean;\n /** Null matches every card. */\n when?: RuleGroup | null;\n target: IntakeRouteTarget;\n /** The events the route handles; unset files new issues and pull requests (`work_item.created`). */\n on?: RouteEvent[];\n /** Writes the route as 0.28 did, moving cards on `pull_request.opened` and filing none: how a deleted one is restored. */\n pullRequestOpenedMovesOnly?: true;\n}\n\nexport interface StoredIntakeRouteRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n name: string;\n enabled: boolean;\n position: number;\n when: RuleGroup | null;\n target: { boardKey: string; phaseKey: string | null; joinClosedIssue: boolean; moveToBoardKey: string | null };\n on: RouteEvent[];\n /**\n * Set on a route stored before `pull_request.opened` filed pull requests with no card (0.28): it\n * names that event and only moves cards on it, as it always has. Writing `on` again clears it.\n */\n pullRequestOpenedMovesOnly?: true;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n}\n\nexport type StoredBoardErrorCode =\n | 'board_exists'\n | 'board_not_found'\n | 'revision_mismatch'\n | 'intake_route_not_found'\n | 'intake_route_set_mismatch'\n | 'intake_route_limit'\n | 'invalid_intake_route'\n | 'intake_order_set_mismatch'\n | 'intake_decision_not_found'\n | 'invalid_intake_cursor';\n\n/** A board's most intake routes. */\nexport const MAX_INTAKE_ROUTES_PER_BOARD = 100;\n\n/**\n * How an arrival was decided; `rule_skipped` warns that a card-move rule matched but its target\n * couldn't take the card, and `rule_retired` that Factory switched off a join route an admin had\n * changed, whose work no rule does now.\n */\nexport type IntakeDecisionOutcome = 'placed' | 'not_routed' | 'rule_skipped' | 'rule_retired';\n\n/**\n * Which evaluator decides where an arrival goes: `route-list` is the old one, which projects created\n * before `intake-order` shipped keep until an admin switches them.\n */\nexport type IntakeEvaluator = 'route-list' | 'intake-order';\n\n/**\n * `derived` while the order still follows the route list: every rule write re-derives it. `explicit`\n * once an admin sets it.\n */\nexport type IntakeOrderOrigin = 'derived' | 'explicit';\n\nexport interface StoredIntakeOrder {\n /** Board keys in the order intake checks them. */\n boardKeys: string[];\n origin: IntakeOrderOrigin;\n}\n\nexport interface IntakeDecisionInput {\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey?: string | null;\n routeId?: string | null;\n reason?: string | null;\n sourceKey?: string | null;\n title: string;\n url?: string | null;\n /** The arrival as it was decided on; kept so Route again can file it. */\n arrival?: Record<string, unknown> | null;\n}\n\nexport interface StoredIntakeDecisionRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey: string | null;\n routeId: string | null;\n reason: string | null;\n sourceKey: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decidedAt: Date;\n resolvedAt: Date | null;\n resolvedBy: string | null;\n}\n\n// Work's routes are its seed data, kept with the board they target.\nexport {\n DEFAULT_INTAKE_ROUTE,\n OUTSIDE_PULL_REQUEST_INTAKE_ROUTE,\n PULL_REQUEST_INTAKE_ROUTE,\n CLOSED_COMPLETED_ROUTE,\n CLOSED_CANCELED_ROUTE,\n REOPENED_ROUTE,\n PULL_REQUEST_MERGED_ROUTE,\n PULL_REQUEST_CLOSED_ROUTE,\n PULL_REQUEST_CLOSED_ISSUE_ROUTE,\n PULL_REQUEST_UPDATED_ROUTE,\n PULL_REQUEST_REVIEW_REQUESTED_ROUTE,\n LINKED_PULL_REQUEST_ROUTE,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n CATCH_ALL_INTAKE_ROUTE,\n DEFAULT_INTAKE_ROUTES,\n} from '../../../boards/work-routes.js';\n\n/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */\nconst ORIGINAL_DEFAULT_KEYS = ['outside-authors'];\n\n/** Who the default intake routes are created and last updated by. */\nexport const DEFAULT_INTAKE_ROUTE_ACTOR = 'factory';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface VersionRow extends Record<string, unknown> {\n version: string;\n /** Keys of the boards Factory stored in the project; null on rows written before the list. */\n seeded_boards: string[] | null;\n /** Keys of the board migrations applied to the project; null before the first one. */\n applied_migrations: string[] | null;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\ninterface IntakeRouteRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n name: string;\n enabled: boolean;\n position: number;\n when_condition: RuleGroup | null;\n board_key: string;\n phase_key: string | null;\n /** Null on rows written before routes named events: they place new cards. */\n on_events: RouteEvent[] | null;\n join_closed_issue: boolean | null;\n /** Null on rows written before `pull_request.opened` filed pull requests: there it only moves a card. */\n opened_files_pull_requests?: boolean | null;\n move_to_board_key: string | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface IntakeRouteLockRow extends Record<string, unknown> {\n /** Keys of the `DEFAULT_INTAKE_ROUTES` added to the project; null on rows written before the list. */\n seeded_defaults: string[] | null;\n intake_order: string[] | null;\n /** Null while derived. */\n intake_order_origin: 'explicit' | null;\n /** Null on projects created before the setting: they use `route-list`. */\n intake_evaluator?: IntakeEvaluator | null;\n}\n\ninterface IntakeDecisionRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n idempotency_key: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n board_key: string | null;\n route_id: string | null;\n reason: string | null;\n source_key: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decided_at: Date;\n resolved_at: Date | null;\n resolved_by: string | null;\n}\n\nfunction toIntakeDecisionRecord(row: IntakeDecisionRow): StoredIntakeDecisionRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n idempotencyKey: row.idempotency_key,\n outcome: row.outcome,\n evaluator: row.evaluator,\n boardKey: row.board_key,\n routeId: row.route_id,\n reason: row.reason,\n sourceKey: row.source_key,\n title: row.title,\n url: row.url,\n arrival: row.arrival,\n decidedAt: row.decided_at,\n resolvedAt: row.resolved_at,\n resolvedBy: row.resolved_by,\n };\n}\n\nfunction seededDefaults(lock: IntakeRouteLockRow): string[] {\n return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;\n}\n\nfunction missingDefaults(lock: IntakeRouteLockRow): (typeof DEFAULT_INTAKE_ROUTES)[number][] {\n const seeded = new Set(seededDefaults(lock));\n return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst INTAKE_ROUTES = 'factory_intake_routes';\nconst INTAKE_ROUTE_LOCKS = 'factory_intake_route_locks';\nconst INTAKE_DECISIONS = 'factory_intake_decisions';\nconst MAX_WRITE_ATTEMPTS = 3;\nconst MIGRATION_ACTOR = 'factory';\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: currentRuleGroup(row.auto_start_when),\n exitTool: row.exit_tool?.autoApproveWhen\n ? { ...row.exit_tool, autoApproveWhen: currentRuleGroup(row.exit_tool.autoApproveWhen) }\n : row.exit_tool,\n tools: row.tools ?? null,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** Runs inside a board write's transaction, before the board is written. */\nexport type BoardWriteStep = (ops: FactoryStorageOps) => Promise<void>;\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(INTAKE_DECISIONS, {});\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n await this.ops.deleteMany(INTAKE_ROUTES, {});\n await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n return readStoredBoard(this.ops, scope, key);\n }\n\n /**\n * Creates a board through the API. `before` runs in the same transaction, once the key is known\n * to be free. A row under the key that `over` accepts does not hold it: the board is written\n * over that row.\n */\n async create(\n scope: StoredBoardScope,\n input: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n over?: (row: StoredBoardRecord) => boolean,\n ): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const taken = rows.find(row => row.board_key === input.key);\n const stored = taken && over ? await readStoredBoard(ops, scope, input.key) : null;\n if (taken && !(stored && over?.(stored))) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await before?.(ops);\n if (taken) await writeBoard(ops, scope, taken, input, actor);\n else await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string; before?: BoardWriteStep },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await options.before?.(ops);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Stores Factory's boards (Work, app and seed boards) in the project, each key once: a key the\n * project has had before is skipped even if its board was deleted since, and a stored board is\n * never rewritten. A project stored before the list was kept counts the boards it has as stored.\n * Reads one row when every key was stored before. Returns the keys it inserted.\n *\n * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that\n * already has any board, such as one an app stored under that key, is left as it is. The key\n * is still recorded as stored, so it never goes in later, even after the project's boards are\n * deleted: that project chose its boards, and Work is never added beside or after them. The\n * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so\n * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded\n * as the inserted boards' creator. `before` runs in the same\n * transaction ahead of each board it inserts.\n */\n async seedBoards(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor?: string;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n } = {},\n ): Promise<string[]> {\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.seeded_boards && boards.every(board => marker.seeded_boards!.includes(board.key))) return [];\n return this.#insertOnce(scope, boards, {\n actor: options.actor ?? DEFAULT_INTAKE_ROUTE_ACTOR,\n skipSeeded: true,\n onlyIntoEmpty: options.onlyIntoEmpty ?? [],\n intoEmpty: options.intoEmpty ?? [],\n before: options.before,\n });\n }\n\n /** The keys of the boards Factory stored in the project; null before it kept the list. */\n async seededBoardKeys(scope: StoredBoardScope): Promise<string[] | null> {\n return (await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))?.seeded_boards ?? null;\n }\n\n /**\n * Rewrites the board stored under `seed.key` to `seed` at its next revision when `when` says the\n * row is nobody's: one an earlier release seeded for a board Factory no longer has, under a key\n * the app now defines. `before` runs in the same transaction. Returns whether it rewrote the row.\n */\n async adoptSeed(\n scope: StoredBoardScope,\n seed: StoredBoardInput,\n options: { when: (row: StoredBoardRecord) => boolean; before?: BoardWriteStep },\n ): Promise<boolean> {\n return this.#write(scope, async ops => {\n const stored = await readStoredBoard(ops, scope, seed.key);\n if (!stored || !options.when(stored)) return { result: false, changed: false };\n await options.before?.(ops);\n await writeBoard(ops, scope, await findBoard(ops, scope, seed.key), seed, DEFAULT_INTAKE_ROUTE_ACTOR);\n return { result: true, changed: true };\n });\n }\n\n /**\n * Inserts a board into the project unless one is stored under its key, and records the key as\n * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.\n * Returns whether it inserted the board. `before` runs in the same transaction when it does.\n */\n async insertIfMissing(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n ): Promise<boolean> {\n return (await this.#insertOnce(scope, [board], { actor, skipSeeded: false, before })).length > 0;\n }\n\n async #insertOnce(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor: string;\n skipSeeded: boolean;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n },\n ): Promise<string[]> {\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const marker = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const present = new Set(rows.map(row => row.board_key));\n const seeded = new Set(marker.seeded_boards ?? present);\n // The `intoEmpty` boards go into a project with no boards, first; `onlyIntoEmpty` keys then\n // go in only when nothing is stored yet, so a project holding them gets no default beside them.\n const candidates = [...(rows.length === 0 ? (options.intoEmpty ?? []) : []), ...boards];\n let position = nextPosition(rows);\n const inserted: string[] = [];\n for (const board of candidates) {\n if (present.has(board.key) || (options.skipSeeded && seeded.has(board.key))) continue;\n if (present.size > 0 && options.onlyIntoEmpty?.includes(board.key)) continue;\n await options.before?.(ops, board.key);\n await insertBoard(ops, scope, board, { position: position++, actor: options.actor });\n present.add(board.key);\n inserted.push(board.key);\n }\n const next = [...new Set([...seeded, ...candidates.map(board => board.key)])];\n const unchanged = marker.seeded_boards !== null && next.length === marker.seeded_boards.length;\n if (inserted.length === 0 && unchanged) return inserted;\n // Compare-and-set on the version, and every marker write takes a new one: two replicas\n // recording different keys can't both match the version they read, so neither key is lost.\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: marker.version },\n {\n seeded_boards: next,\n version: randomUUID(),\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return inserted;\n });\n }\n\n /**\n * Runs each migration the project hasn't had yet, once: the keys applied are recorded on the\n * project's version row in the same transaction as the board writes, and the compare-and-set on\n * its version makes a concurrent first load retry from fresh reads, where it finds them applied.\n * A migration whose board the project doesn't have is recorded without running, and the version\n * only changes when a board was rewritten. Reads one row\n * when every key was applied before. Returns what each migration that rewrote a board filled.\n */\n async applyBoardMigrations(\n scope: StoredBoardScope,\n migrations: readonly StoredBoardMigration[],\n /**\n * Read through the transaction's `ops`, again on every retry, and only when a migration is still\n * pending, so what it reports is as fresh as the boards the migrations rewrite.\n */\n context: (ops: FactoryStorageOps) => Promise<BoardMigrationContext> = async () => EMPTY_MIGRATION_CONTEXT,\n ): Promise<AppliedBoardMigration[]> {\n if (migrations.length === 0) return [];\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.applied_migrations && migrations.every(({ key }) => marker.applied_migrations!.includes(key))) {\n return [];\n }\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const current = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const applied = current.applied_migrations ?? [];\n const pending = migrations.filter(({ key }) => !applied.includes(key));\n if (pending.length === 0) return [];\n const project = await context(ops);\n const changed: AppliedBoardMigration[] = [];\n for (const migration of pending) {\n const rows =\n migration.boardKey === null\n ? await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))\n : await ops.findMany<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: migration.boardKey });\n for (const row of rows) {\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n const result = migration.migrate(toRecord(row, phases), project);\n if (!result) continue;\n await writeBoard(ops, scope, row, { ...result.board, key: row.board_key }, MIGRATION_ACTOR);\n changed.push({ key: migration.key, boardKey: row.board_key, filled: result.filled });\n }\n }\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: current.version },\n {\n applied_migrations: [...applied, ...pending.map(({ key }) => key)],\n // Only a rewritten board is news to the other replicas' caches.\n version: changed.length > 0 ? randomUUID() : current.version,\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return changed;\n });\n }\n\n /** Rewrites a board to `definition` (Factory's current one for its key), raising its revision. */\n async resetTo(\n scope: StoredBoardScope,\n key: string,\n definition: StoredBoardInput,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { ...definition, key }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Deletes a board, its phases and its intake routes in one transaction, and takes it out of the\n * intake order. Returns the routes it deleted, for the caller to audit.\n */\n async delete(\n scope: StoredBoardScope,\n key: string,\n options: { expectedRevision: number },\n ): Promise<{ intakeRoutes: StoredIntakeRouteRecord[] }> {\n await this.#ensureIntakeRoutes(scope);\n return this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n const routes = await lockIntakeRoutes(ops, scope);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n const deleted = routes.filter(route => route.board_key === key);\n if (deleted.length > 0) {\n // The surviving routes keep their positions; readers sort over the gaps.\n await ops.deleteMany(INTAKE_ROUTES, { ...scopeWhere(scope), board_key: key });\n await forgetDerivedIntakeOrder(ops, scope);\n }\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n if (lock.intake_order?.includes(key)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: lock.intake_order.filter(other => other !== key),\n });\n }\n return { result: { intakeRoutes: deleted.map(toIntakeRouteRecord) }, changed: true };\n });\n }\n\n /**\n * The project's intake routes in the order they are tried, or one board's list when `boardKey`\n * is set; Factory's `DEFAULT_INTAKE_ROUTES` are added once each.\n */\n async listIntakeRoutes(\n scope: StoredBoardScope,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n const rows = await readIntakeRoutes(this.ops, scope);\n return rows\n .filter(row => options.boardKey === undefined || row.board_key === options.boardKey)\n .map(toIntakeRouteRecord);\n }\n\n /**\n * The project's intake order, derived from the route list the first time it is read and kept up\n * to date with its boards (see `reconcileIntakeOrder`), with the migration marker. Its boards are\n * the stored ones plus `options.boards` (the caller's registry, so a code board keeps its place).\n */\n async readIntakeOrder(\n scope: StoredBoardScope,\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n const current = await this.#intakeOrderState(this.ops, scope, options.boards);\n if (current.lock.intake_order && sameKeys(current.lock.intake_order, current.boardKeys)) {\n return toIntakeOrder(current.lock, current.boardKeys);\n }\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const fresh = await this.#intakeOrderState(ops, scope, options.boards);\n if (!fresh.lock.intake_order || !sameKeys(fresh.lock.intake_order, fresh.boardKeys)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_order: fresh.boardKeys });\n }\n return toIntakeOrder(fresh.lock, fresh.boardKeys);\n });\n }\n\n /**\n * Sets the project's intake order, which then no longer follows the route list; `boardKeys` must\n * name every board of the project exactly once: its stored boards, or `options.boards` when given\n * (the caller's registry, code boards too).\n */\n async setIntakeOrder(\n scope: StoredBoardScope,\n boardKeys: string[],\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const keys = new Set(\n options.boards ?? (await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))).map(board => board.board_key),\n );\n if (\n boardKeys.length !== keys.size ||\n new Set(boardKeys).size !== boardKeys.length ||\n boardKeys.some(key => !keys.has(key))\n ) {\n throw new StoredBoardError(\n 'intake_order_set_mismatch',\n 'The intake order must list every board of the project exactly once; reload the boards and try again.',\n );\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: boardKeys,\n intake_order_origin: 'explicit',\n });\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n return toIntakeOrder(lock, boardKeys);\n });\n }\n\n /** The project's own evaluator; null for a project created before the setting, which uses `route-list`. */\n async intakeEvaluator(scope: StoredBoardScope): Promise<IntakeEvaluator | null> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n return lock?.intake_evaluator ?? null;\n }\n\n /** Switches the project's evaluator; returns the setting it had (null: none). */\n async setIntakeEvaluator(scope: StoredBoardScope, evaluator: IntakeEvaluator): Promise<IntakeEvaluator | null> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_evaluator: evaluator });\n return lock.intake_evaluator ?? null;\n });\n }\n\n /** Records how intake decided an arrival; a redelivery under the same key replaces the row. */\n async recordIntakeDecision(\n scope: StoredBoardScope,\n input: IntakeDecisionInput,\n now = new Date(),\n ): Promise<StoredIntakeDecisionRecord> {\n const row = await this.ops.upsertOne<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n ['org_id', 'factory_project_id', 'idempotency_key'],\n {\n ...scopeWhere(scope),\n idempotency_key: input.idempotencyKey,\n outcome: input.outcome,\n evaluator: input.evaluator,\n board_key: input.boardKey ?? null,\n route_id: input.routeId ?? null,\n reason: input.reason ?? null,\n source_key: input.sourceKey ?? null,\n title: input.title,\n url: input.url ?? null,\n arrival: input.arrival ?? null,\n decided_at: now,\n resolved_at: null,\n resolved_by: null,\n },\n );\n return toIntakeDecisionRecord(row);\n }\n\n async getIntakeDecision(scope: StoredBoardScope, id: string): Promise<StoredIntakeDecisionRecord | null> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, { ...scopeWhere(scope), id });\n return row ? toIntakeDecisionRecord(row) : null;\n }\n\n /**\n * Items no board took and nobody has filed since, oldest first, `limit` at a time; pass\n * `nextCursor` back as `cursor` for the next page.\n */\n async listNotRouted(\n scope: StoredBoardScope,\n options: { limit?: number; cursor?: string } = {},\n ): Promise<{ notRouted: StoredIntakeDecisionRecord[]; nextCursor: string | null }> {\n const limit = options.limit ?? 50;\n const after = options.cursor === undefined ? undefined : decodeDecisionCursor(options.cursor);\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n {\n orderBy: DECISION_ORDER,\n limit: limit + 1,\n ...(after && { cursor: { values: [after.decidedAt, after.id] } }),\n },\n );\n const page = rows.slice(0, limit).map(toIntakeDecisionRecord);\n const last = page.at(-1);\n return {\n notRouted: page,\n nextCursor: rows.length > limit && last ? `${last.decidedAt.toISOString()}_${last.id}` : null,\n };\n }\n\n /** Whether intake turned the source away (Not routed) and nobody has filed it since. */\n async isNotRouted(scope: StoredBoardScope, sourceKey: string): Promise<boolean> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, {\n ...scopeWhere(scope),\n outcome: 'not_routed',\n source_key: sourceKey,\n resolved_at: null,\n });\n return row !== null;\n }\n\n /** The newest `limit` items no board took and nobody has filed since, newest first. */\n async listRecentNotRouted(scope: StoredBoardScope, limit: number): Promise<StoredIntakeDecisionRecord[]> {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n { orderBy: NEWEST_DECISION_ORDER, limit },\n );\n return rows.map(toIntakeDecisionRecord);\n }\n\n /**\n * How many items each intake rule placed since `since`, keyed by rule id. Reads placed rows\n * newest first, a page at a time, and stops at the first one older than `since`.\n */\n async countPlacedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, number>> {\n const pageSize = options.pageSize ?? 500;\n const counts: Record<string, number> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'placed' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return counts;\n if (row.route_id) counts[row.route_id] = (counts[row.route_id] ?? 0) + 1;\n }\n if (rows.length < pageSize) return counts;\n cursor = rows.at(-1);\n }\n }\n\n /**\n * How often each card-move rule was skipped since `since`, with its newest skip, keyed by rule id.\n * Reads skipped rows newest first, a page at a time, and stops at the first one older than `since`.\n */\n async summarizeSkippedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, { count: number; latest: StoredIntakeDecisionRecord }>> {\n const pageSize = options.pageSize ?? 500;\n const summary: Record<string, { count: number; latest: StoredIntakeDecisionRecord }> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'rule_skipped' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return summary;\n if (!row.route_id) continue;\n const seen = summary[row.route_id];\n if (seen) seen.count += 1;\n else summary[row.route_id] = { count: 1, latest: toIntakeDecisionRecord(row) };\n }\n if (rows.length < pageSize) return summary;\n cursor = rows.at(-1);\n }\n }\n\n /** Marks the Not routed rows for a source resolved once a card is filed for it. Returns how many. */\n async resolveNotRouted(scope: StoredBoardScope, sourceKey: string, by: string, now = new Date()): Promise<number> {\n return this.ops.updateMany(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', source_key: sourceKey, resolved_at: null },\n { resolved_at: now, resolved_by: by },\n );\n }\n\n async #intakeOrderState(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n extra: readonly string[] = [],\n ): Promise<{ lock: IntakeRouteLockRow; boardKeys: string[] }> {\n const [lock, boards, routes] = await Promise.all([\n ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)),\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n readIntakeRoutes(ops, scope),\n ]);\n const sidebar = boards\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(board => board.board_key);\n sidebar.push(...extra.filter(key => !sidebar.includes(key)));\n const records = routes.map(toIntakeRouteRecord);\n const stored = lock!.intake_order ?? deriveIntakeOrder(records, sidebar);\n return { lock: lock!, boardKeys: reconcileIntakeOrder(stored, sidebar, records) };\n }\n\n async getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null> {\n const row = await this.ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n return row ? toIntakeRouteRecord(row) : null;\n }\n\n /**\n * Adds a route after the project's last one. A route that places new cards goes just ahead of the\n * first route that takes every new card instead, since after it it would never place one.\n */\n async createIntakeRoute(\n scope: StoredBoardScope,\n input: StoredIntakeRouteInput,\n actor: string,\n ): Promise<StoredIntakeRouteRecord> {\n const id = randomUUID();\n checkRouteEvents(input.on ?? DEFAULT_ROUTE_EVENTS, input.when ?? null);\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n if (boardRouteCount(rows, input.target.boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n const position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n await insertIntakeRoute(ops, scope, { id, input, position, actor });\n await forgetDerivedIntakeOrder(ops, scope);\n // Ahead of the catch-all taking each kind it files, the later one when they differ, so a route\n // filing issues and pull requests stays behind a catch-all for pull requests, as it always\n // has. A kind no route catches reaches it at the end, so it stays there.\n const catchAlls = [\n ...arrivalKinds({\n on: input.on ?? DEFAULT_ROUTE_EVENTS,\n ...(input.pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true }),\n }),\n ].map(kind => rows.findIndex(row => catchesEveryNewCard(row, kind)));\n const ahead = catchAlls.length > 0 && !catchAlls.includes(-1) ? Math.max(...catchAlls) : -1;\n if (ahead >= 0) {\n const added = (await readIntakeRoutes(ops, scope)).find(row => row.id === id)!;\n const target = rows[ahead]!;\n const previous = ahead === 0 ? -1 : rows[ahead - 1]!.position;\n if (target.position - previous > 1) {\n // A deleted route left a free slot just ahead of the catch-all: take it and move nothing.\n await updateIntakeRouteRow(ops, added, { position: target.position - 1 });\n } else {\n // Move the catch-all and what follows it one place down; the routes ahead stay put.\n await moveIntakeRoutes(\n ops,\n [added, ...rows.slice(ahead)].map((row, index) => ({ row, position: target.position + index })),\n actor,\n );\n }\n }\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Changes the fields `patch` names; the route keeps its place in the order. */\n async updateIntakeRoute(\n scope: StoredBoardScope,\n id: string,\n patch: Partial<StoredIntakeRouteInput>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredIntakeRouteRecord> {\n await this.#transact(async ops => {\n // Lock first, as every route write does, so it can't deadlock against a reorder.\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n const boardKey = patch.target?.boardKey;\n if (\n boardKey !== undefined &&\n boardKey !== row.board_key &&\n boardRouteCount(rows, boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD\n ) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n checkRouteEvents(patch.on ?? routeEvents(row), patch.when !== undefined ? patch.when : row.when_condition);\n await updateIntakeRouteRow(ops, row, {\n ...(patch.on !== undefined && { on_events: patch.on }),\n ...(patch.name !== undefined && { name: patch.name }),\n ...(patch.enabled !== undefined && { enabled: patch.enabled }),\n ...(patch.when !== undefined && { when_condition: patch.when }),\n ...(patch.target !== undefined && {\n board_key: patch.target.boardKey,\n phase_key: patch.target.phaseKey ?? null,\n join_closed_issue: patch.target.joinClosedIssue ?? false,\n move_to_board_key: patch.target.moveToBoardKey ?? null,\n }),\n updated_by: options.actor,\n });\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Deletes a route; the others keep their positions, and readers sort over the gap. */\n async deleteIntakeRoute(scope: StoredBoardScope, id: string, options: { expectedRevision: number }): Promise<void> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n if ((await ops.deleteMany(INTAKE_ROUTES, { id: row.id, revision: row.revision })) === 0) {\n throw new ConcurrentBoardWrite();\n }\n await forgetDerivedIntakeOrder(ops, scope);\n });\n }\n\n /**\n * Puts the project's routes in the order of `ids`, which must name every route exactly once. With\n * `boardKey`, `ids` names every route of that board instead: they trade the places the board's\n * routes hold, and every other board's routes keep theirs. Returns the routes reordered.\n */\n async reorderIntakeRoutes(\n scope: StoredBoardScope,\n ids: string[],\n actor: string,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n const { boardKey } = options;\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const scoped = boardKey === undefined ? rows : rows.filter(row => row.board_key === boardKey);\n const byId = new Map(scoped.map(row => [row.id, row]));\n if (ids.length !== scoped.length || new Set(ids).size !== ids.length || ids.some(id => !byId.has(id))) {\n throw new StoredBoardError(\n 'intake_route_set_mismatch',\n boardKey === undefined\n ? 'The order must list every intake route of the project exactly once; reload the routes and try again.'\n : `The order must list every intake rule of board \"${boardKey}\" exactly once; reload the rules and try again.`,\n );\n }\n const queue = ids.map(id => byId.get(id)!);\n if (boardKey === undefined) {\n await placeIntakeRoutes(ops, queue, actor);\n } else {\n // The board's routes trade the position slots the board already holds, so every other\n // board's routes keep their positions and revisions.\n const slots = scoped.map(row => row.position);\n await moveIntakeRoutes(\n ops,\n queue.map((row, index) => ({ row, position: slots[index]! })),\n actor,\n );\n }\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return this.listIntakeRoutes(scope, { boardKey });\n }\n\n /**\n * Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of\n * `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row\n * records every default it added, so a project whose admin deleted one doesn't get it back. Runs\n * before, never inside, a write's transaction: the lock taken there must always be an update.\n */\n async #ensureIntakeRoutes(scope: StoredBoardScope): Promise<void> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n if (lock && missingDefaults(lock).length === 0) return;\n await this.#transact(async ops => {\n if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);\n // A racing first read inserted the lock row first: this one fails on the unique index and\n // retries, taking the lock above.\n else\n await ops.insertOne(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), locked_at: new Date(), seeded_defaults: [] });\n // Read under the lock: a racing seeder that committed first already added what it listed.\n const current = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n const missing = missingDefaults(current);\n if (missing.length === 0) return;\n const rows = await readIntakeRoutes(ops, scope);\n const retired = new Set<string>();\n // Pull requests link to the card of the issue they close on their own now: a route that\n // joined them is switched off, and kept so its history stays readable.\n // One an admin had changed is named in the decision log: the linked rule doesn't do all it did.\n if (missing.some(({ key }) => key === LINKED_PULL_REQUEST_ROUTE_KEY)) {\n for (const row of rows) {\n if (!row.join_closed_issue || !row.enabled) continue;\n await updateIntakeRouteRow(ops, row, { enabled: false, updated_by: DEFAULT_INTAKE_ROUTE_ACTOR });\n retired.add(row.id);\n if (isShippedJoinRoute(row)) continue;\n await ops.upsertOne(INTAKE_DECISIONS, ['org_id', 'factory_project_id', 'idempotency_key'], {\n ...scopeWhere(scope),\n idempotency_key: `rule-retired:${row.id}`,\n outcome: 'rule_retired',\n evaluator: current.intake_evaluator ?? 'route-list',\n board_key: row.board_key,\n route_id: row.id,\n reason:\n 'Switched off: pull requests now link to the card of the issue they close on their own, and only the rule `Trusted pull requests take a waiting issue to Review` moves a waiting card. Add a card-move rule on pull_request.opened to move cards the way this route did.',\n source_key: null,\n title: row.name,\n url: null,\n arrival: null,\n decided_at: new Date(),\n resolved_at: null,\n resolved_by: null,\n });\n }\n }\n let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n const first: string[] = [];\n const perBoard = new Map<string, number>();\n // Only a project no default was added to yet is new.\n const newProject = seededDefaults(current).length === 0;\n for (const { key, route, first: leads, newProjectsOnly } of missing) {\n if (newProjectsOnly && !newProject) continue;\n // A board at the limit keeps its own routes; the default counts as added all the same. The\n // linked rule takes the slot of a join route it switched off.\n const count =\n perBoard.get(route.target.boardKey) ??\n boardRouteCount(\n key === LINKED_PULL_REQUEST_ROUTE_KEY ? rows.filter(row => !retired.has(row.id)) : rows,\n route.target.boardKey,\n );\n if (count >= MAX_INTAKE_ROUTES_PER_BOARD) continue;\n perBoard.set(route.target.boardKey, count + 1);\n const id = randomUUID();\n await insertIntakeRoute(ops, scope, {\n id,\n input: route,\n position: position++,\n actor: DEFAULT_INTAKE_ROUTE_ACTOR,\n });\n if (leads) first.push(id);\n }\n // A project that had routes before gets a leading default ahead of them.\n if (first.length > 0 && rows.length > 0) {\n const placed = await readIntakeRoutes(ops, scope);\n const leading = new Set(first);\n await placeIntakeRoutes(ops, [\n ...first.map(id => placed.find(row => row.id === id)!),\n ...placed.filter(row => !leading.has(row.id)),\n ]);\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)],\n });\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n return this.#transact(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n }\n\n /**\n * Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it\n * directly: routes are read uncached, so they leave the board definition version alone.\n */\n async #transact<T>(fn: (ops: FactoryStorageOps) => Promise<T>): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(fn);\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\n/** The project's board under `key`, read through `ops` so a caller inside a transaction reads within it. */\nexport async function readStoredBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n key: string,\n): Promise<StoredBoardRecord | null> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n tools: phase.tools?.length ? phase.tools : null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n\n/**\n * A row's events as stored. One written before routes named events has none: it reads as the legacy\n * `work_item.created`, filing issues and pull requests alike, as it always has (rows are never rewritten).\n */\nfunction routeEvents(row: IntakeRouteRow): RouteEvent[] {\n return row.on_events ? [...row.on_events] : [...DEFAULT_ROUTE_EVENTS];\n}\n\n/** A row's events with what they mean on it: `pull_request.opened` only moves a card on a row from before it filed. */\nfunction routeArrivals(row: IntakeRouteRow): RouteArrivals {\n const on = routeEvents(row);\n return {\n on,\n pullRequestOpenedMovesOnly: row.opened_files_pull_requests !== true && on.includes('pull_request.opened'),\n };\n}\n\nfunction checkRouteEvents(on: readonly string[], when: RuleGroup | null): void {\n const problem = routeEventsProblem(on, when);\n if (problem) throw new StoredBoardError('invalid_intake_route', problem);\n}\n\nfunction toIntakeRouteRecord(row: IntakeRouteRow): StoredIntakeRouteRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n name: row.name,\n enabled: row.enabled,\n position: row.position,\n when: currentRuleGroup(row.when_condition),\n target: {\n boardKey: row.board_key,\n phaseKey: row.phase_key,\n joinClosedIssue: row.join_closed_issue === true,\n moveToBoardKey: row.move_to_board_key ?? null,\n },\n on: routeEvents(row),\n ...(routeArrivals(row).pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true as const }),\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\nconst DECISION_ORDER: [string, 'asc'][] = [\n ['decided_at', 'asc'],\n ['id', 'asc'],\n];\nconst NEWEST_DECISION_ORDER: [string, 'desc'][] = [\n ['decided_at', 'desc'],\n ['id', 'desc'],\n];\n\nfunction decodeDecisionCursor(cursor: string): { decidedAt: Date; id: string } {\n const sep = cursor.lastIndexOf('_');\n const decidedAt = new Date(cursor.slice(0, sep));\n const id = cursor.slice(sep + 1);\n if (sep <= 0 || Number.isNaN(decidedAt.getTime()) || !id) {\n throw new StoredBoardError('invalid_intake_cursor', 'The cursor is not one this list returned.');\n }\n return { decidedAt, id };\n}\n\n/**\n * Stamps a project being created with the `intake-order` evaluator, through `ops`, the creating\n * transaction's, so the project and its setting commit together. A new project has no lock row yet;\n * its first intake read adds the default routes to this one. Its intake order is its own from the\n * start (`explicit`, empty): deriving one from the route list is for projects that had one before,\n * and would keep Work, whose defaults lead the list, ahead of every board added later. Each board\n * slots in as it comes, just above the first board that takes every new card.\n */\nexport async function stampNewProjectIntake(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.insertOne(INTAKE_ROUTE_LOCKS, {\n ...scopeWhere(scope),\n locked_at: new Date(),\n seeded_defaults: [],\n intake_order: [],\n intake_order_origin: 'explicit',\n intake_evaluator: 'intake-order',\n });\n}\n\nfunction toIntakeOrder(lock: IntakeRouteLockRow, boardKeys: string[]): StoredIntakeOrder {\n return { boardKeys, origin: lock.intake_order_origin ?? 'derived' };\n}\n\n/**\n * A rule write changes what a derived order would be: drop it, so the next read derives it afresh.\n * An order an admin set stays.\n */\nasync function forgetDerivedIntakeOrder(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), intake_order_origin: null }, { intake_order: null });\n}\n\nfunction sameKeys(left: readonly string[], right: readonly string[]): boolean {\n return left.length === right.length && left.every((key, index) => key === right[index]);\n}\n\nfunction boardRouteCount(rows: readonly IntakeRouteRow[], boardKey: string): number {\n return rows.filter(row => row.board_key === boardKey).length;\n}\n\n/** Whether a stored join route is still the one projects were given, which the linked rule replaces. */\nfunction isShippedJoinRoute(row: IntakeRouteRow): boolean {\n return (\n row.board_key === RETIRED_JOIN_ROUTE.target.boardKey &&\n row.phase_key === RETIRED_JOIN_ROUTE.target.phaseKey &&\n isDeepStrictEqual(currentRuleGroup(row.when_condition), RETIRED_JOIN_ROUTE.when)\n );\n}\n\n/** Whether `row` files every new issue, or pull request, that reaches it, as the seeded \"Everything else\" route does. */\nfunction catchesEveryNewCard(row: IntakeRouteRow, kind: ArrivalKind): boolean {\n return (\n row.enabled &&\n !row.join_closed_issue &&\n kindsTakenWhole({ when: row.when_condition, ...routeArrivals(row) }).includes(kind)\n );\n}\n\nasync function readIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n const rows = await ops.findMany<IntakeRouteRow>(INTAKE_ROUTES, scopeWhere(scope));\n return rows.sort((left, right) => left.position - right.position);\n}\n\nfunction intakeRouteNotFound(id: string): StoredBoardError {\n return new StoredBoardError('intake_route_not_found', `Intake route \"${id}\" does not exist in this project.`);\n}\n\nfunction checkIntakeRouteRevision(row: IntakeRouteRow, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Intake route \"${row.name}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\n/** Sets columns on a route row and raises its revision, unless another writer changed it first. */\nasync function updateIntakeRouteRow(\n ops: FactoryStorageOps,\n row: IntakeRouteRow,\n set: Partial<IntakeRouteRow>,\n): Promise<number> {\n const revision = row.revision + 1;\n const updated = await ops.updateMany(\n INTAKE_ROUTES,\n { id: row.id, revision: row.revision },\n { ...set, revision, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return revision;\n}\n\nasync function insertIntakeRoute(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n route: { id: string; input: StoredIntakeRouteInput; position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<IntakeRouteRow>(INTAKE_ROUTES, {\n id: route.id,\n ...scopeWhere(scope),\n name: route.input.name,\n enabled: route.input.enabled ?? true,\n position: route.position,\n when_condition: route.input.when ?? null,\n board_key: route.input.target.boardKey,\n phase_key: route.input.target.phaseKey ?? null,\n on_events: route.input.on ?? null,\n join_closed_issue: route.input.target.joinClosedIssue ?? false,\n opened_files_pull_requests: route.input.pullRequestOpenedMovesOnly ? null : true,\n move_to_board_key: route.input.target.moveToBoardKey ?? null,\n revision: 1,\n created_by: route.actor,\n created_at: now,\n updated_by: route.actor,\n updated_at: now,\n });\n}\n\n/**\n * Takes the project's route lock and reads the routes. Writes that add, delete or move routes\n * call this first, so they run one after another and each reads what the one before committed.\n */\nasync function lockIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n if ((await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: new Date() })) !== 1) {\n throw new ConcurrentBoardWrite();\n }\n return readIntakeRoutes(ops, scope);\n}\n\n/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */\nasync function placeIntakeRoutes(ops: FactoryStorageOps, rows: IntakeRouteRow[], actor?: string): Promise<void> {\n await moveIntakeRoutes(\n ops,\n rows.map((row, position) => ({ row, position })),\n actor,\n );\n}\n\n/**\n * Moves each route of `moves`, read under the project's route lock, to the position named for it.\n * A route already in its place is left alone. Each move parks at a negative position first, so the\n * moves can trade places without meeting the unique position index on the way.\n */\nasync function moveIntakeRoutes(\n ops: FactoryStorageOps,\n moves: { row: IntakeRouteRow; position: number }[],\n actor?: string,\n): Promise<void> {\n const moving = moves.filter(({ row, position }) => row.position !== position);\n const parked = [];\n for (const [index, { row, position }] of moving.entries()) {\n const revision = await updateIntakeRouteRow(ops, row, {\n position: -(index + 1),\n ...(actor !== undefined && { updated_by: actor }),\n });\n parked.push({ id: row.id, revision, position });\n }\n for (const { id, revision, position } of parked) {\n if ((await ops.updateMany(INTAKE_ROUTES, { id, revision }, { position })) !== 1) throw new ConcurrentBoardWrite();\n }\n}\n"],"mappings":";;;;;;;;;AAmIA,MAAM,0BAAiD;CACrD,iBAAiB;CACjB,gCAAgB,IAAI,IAAI;CACxB,kBAAkB,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AAoD;CAC1G,IAAK,MAAM,IAAI,WAAW,oBAAoB,WAAW,KAAK,GAAG,EAAE,2BAAW,IAAI,KAAK,EAAE,CAAC,MAAO,GAC/F,MAAM,IAAI,qBAAqB;CAEjC,OAAO,iBAAiB,KAAK,KAAK;AACpC;;AAGA,eAAe,kBAAkB,KAAwB,MAAwB,OAA+B;CAC9G,MAAM,iBACJ,KACA,KAAK,KAAK,KAAK,cAAc;EAAE;EAAK;CAAS,EAAE,GAC/C,KACF;AACF;;;;;;AAOA,eAAe,iBACb,KACA,OACA,OACe;CACf,MAAM,SAAS,MAAM,QAAQ,EAAE,KAAK,eAAe,IAAI,aAAa,QAAQ;CAC5E,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,eAAe,OAAO,QAAQ,GAAG;EACzD,MAAM,WAAW,MAAM,qBAAqB,KAAK,KAAK;GACpD,UAAU,EAAE,QAAQ;GACpB,GAAI,UAAU,KAAA,KAAa,EAAE,YAAY,MAAM;EACjD,CAAC;EACD,OAAO,KAAK;GAAE,IAAI,IAAI;GAAI;GAAU;EAAS,CAAC;CAChD;CACA,KAAK,MAAM,EAAE,IAAI,UAAU,cAAc,QACvC,IAAK,MAAM,IAAI,WAAW,eAAe;EAAE;EAAI;CAAS,GAAG,EAAE,SAAS,CAAC,MAAO,GAAG,MAAM,IAAI,qBAAqB;AAEpH"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { isDeepStrictEqual } from 'node:util';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport { arrivalKinds, DEFAULT_ROUTE_EVENTS, routeEventsProblem } from '../../../boards/board-events.js';\nimport type { ArrivalKind, RouteArrivals, RouteEvent } from '../../../boards/board-events.js';\nimport type { FactoryPhaseTool } from '../../../boards/define-board.js';\nimport { deriveIntakeOrder, kindsTakenWhole, reconcileIntakeOrder } from '../../../boards/intake-order.js';\nimport {\n DEFAULT_INTAKE_ROUTES,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n RETIRED_JOIN_ROUTE,\n} from '../../../boards/work-routes.js';\nimport { currentRuleGroup } from '../../../rules/rule-group.js';\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport type { RetiredAutomationSettings } from '../projects/base.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n /** The objective the phase's runs pursue as a goal. */\n goal?: { objective: string; maxRuns?: number };\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n /** Factory tools the phase grants the session working the card there. */\n tools?: FactoryPhaseTool[] | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\n/** What a board migration may know about the project besides the board it rewrites. */\nexport interface BoardMigrationContext {\n /** The project switches the boards replaced, as the project last stored them; null when unknown. */\n readonly retiredSettings: RetiredAutomationSettings | null;\n /** The phases of each board that cards sit in, by board key; null when the cards can't be read. */\n readonly occupiedPhases: ReadonlyMap<string, ReadonlySet<string>> | null;\n /**\n * The phases the code board under this key declares; undefined for a board only the project\n * stores. A row that drops one runs without its code rules (`mergeCodeBehaviour`).\n */\n codePhases(boardKey: string): ReadonlySet<string> | undefined;\n /** Tells the operator about a board a migration left as it is. */\n warn(message: string): void;\n}\n\n/** A one-time rewrite of a stored board, keyed so each project gets it once. */\nexport interface StoredBoardMigration {\n key: string;\n /** The board it rewrites; `null` rewrites every board the project stores. */\n boardKey: string | null;\n /** The board to write instead, with what changed; undefined leaves it as it is. */\n migrate(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n ): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined;\n}\n\nconst EMPTY_MIGRATION_CONTEXT: BoardMigrationContext = {\n retiredSettings: null,\n occupiedPhases: new Map(),\n codePhases: () => undefined,\n warn: () => {},\n};\n\nexport interface AppliedBoardMigration {\n key: string;\n boardKey: string;\n filled: string[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport interface IntakeRouteTarget {\n boardKey: string;\n /**\n * Unset lands the card in the board's first phase. On a route that joins a closed issue's\n * card, the phase that card moves to when its board allows it; unset leaves it where it is.\n */\n phaseKey?: string | null;\n /**\n * Files a pull request on the card of the issue it closes, which must be on `boardKey`, as one\n * more source instead of a card of its own. The route doesn't match any other arrival.\n */\n joinClosedIssue?: boolean;\n /**\n * On a route moving existing cards (one naming events besides `work_item.opened`), the board the\n * card moves to, at `phaseKey`. `boardKey` stays the board whose cards the route moves. Unset\n * keeps the card on `boardKey`.\n */\n moveToBoardKey?: string | null;\n}\n\n/** An intake route as it is written. */\nexport interface StoredIntakeRouteInput {\n name: string;\n enabled?: boolean;\n /** Null matches every card. */\n when?: RuleGroup | null;\n target: IntakeRouteTarget;\n /** The events the route handles; unset files new issues and pull requests (`work_item.created`). */\n on?: RouteEvent[];\n /** Writes the route as 0.28 did, moving cards on `pull_request.opened` and filing none: how a deleted one is restored. */\n pullRequestOpenedMovesOnly?: true;\n /**\n * Writes the route as one stored before rules decided outsiders' pull requests, whose card moves\n * skip an outside author's pull request: how a deleted one is restored. `false` lets them match\n * (what every new route gets); on an update, only an explicit `false` clears the gate.\n */\n outsiderPullRequestsGated?: boolean;\n}\n\nexport interface StoredIntakeRouteRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n name: string;\n enabled: boolean;\n position: number;\n when: RuleGroup | null;\n target: { boardKey: string; phaseKey: string | null; joinClosedIssue: boolean; moveToBoardKey: string | null };\n on: RouteEvent[];\n /**\n * Set on a route stored before `pull_request.opened` filed pull requests with no card (0.28): it\n * names that event and only moves cards on it, as it always has. Writing `on` again clears it.\n */\n pullRequestOpenedMovesOnly?: true;\n /**\n * Set on a route stored before rules decided outsiders' pull requests: its card moves skip an\n * outside author's pull request unless its `when` tests `pullRequest.trusted`, as they always\n * have. Edits never change it; only an explicit `outsiderPullRequestsGated: false` patch clears it.\n */\n outsiderPullRequestsGated?: true;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n}\n\nexport type StoredBoardErrorCode =\n | 'board_exists'\n | 'board_not_found'\n | 'revision_mismatch'\n | 'intake_route_not_found'\n | 'intake_route_set_mismatch'\n | 'intake_route_limit'\n | 'invalid_intake_route'\n | 'intake_order_set_mismatch'\n | 'intake_decision_not_found'\n | 'invalid_intake_cursor';\n\n/** A board's most intake routes. */\nexport const MAX_INTAKE_ROUTES_PER_BOARD = 100;\n\n/**\n * How an arrival was decided; `rule_skipped` warns that a card-move rule matched but its target\n * couldn't take the card, and `rule_retired` that Factory switched off a join route an admin had\n * changed, whose work no rule does now.\n */\nexport type IntakeDecisionOutcome = 'placed' | 'not_routed' | 'rule_skipped' | 'rule_retired';\n\n/**\n * Which evaluator decides where an arrival goes: `route-list` is the old one, which projects created\n * before `intake-order` shipped keep until an admin switches them.\n */\nexport type IntakeEvaluator = 'route-list' | 'intake-order';\n\n/**\n * `derived` while the order still follows the route list: every rule write re-derives it. `explicit`\n * once an admin sets it.\n */\nexport type IntakeOrderOrigin = 'derived' | 'explicit';\n\nexport interface StoredIntakeOrder {\n /** Board keys in the order intake checks them. */\n boardKeys: string[];\n origin: IntakeOrderOrigin;\n}\n\nexport interface IntakeDecisionInput {\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey?: string | null;\n routeId?: string | null;\n reason?: string | null;\n sourceKey?: string | null;\n title: string;\n url?: string | null;\n /** The arrival as it was decided on; kept so Route again can file it. */\n arrival?: Record<string, unknown> | null;\n}\n\nexport interface StoredIntakeDecisionRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey: string | null;\n routeId: string | null;\n reason: string | null;\n sourceKey: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decidedAt: Date;\n resolvedAt: Date | null;\n resolvedBy: string | null;\n}\n\n// Work's routes are its seed data, kept with the board they target.\nexport {\n DEFAULT_INTAKE_ROUTE,\n OUTSIDE_PULL_REQUEST_INTAKE_ROUTE,\n PULL_REQUEST_INTAKE_ROUTE,\n CLOSED_COMPLETED_ROUTE,\n CLOSED_CANCELED_ROUTE,\n REOPENED_ROUTE,\n PULL_REQUEST_MERGED_ROUTE,\n PULL_REQUEST_CLOSED_ROUTE,\n PULL_REQUEST_CLOSED_ISSUE_ROUTE,\n PULL_REQUEST_UPDATED_ROUTE,\n PULL_REQUEST_REVIEW_REQUESTED_ROUTE,\n LINKED_PULL_REQUEST_ROUTE,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n CATCH_ALL_INTAKE_ROUTE,\n DEFAULT_INTAKE_ROUTES,\n} from '../../../boards/work-routes.js';\n\n/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */\nconst ORIGINAL_DEFAULT_KEYS = ['outside-authors'];\n\n/** Who the default intake routes are created and last updated by. */\nexport const DEFAULT_INTAKE_ROUTE_ACTOR = 'factory';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface VersionRow extends Record<string, unknown> {\n version: string;\n /** Keys of the boards Factory stored in the project; null on rows written before the list. */\n seeded_boards: string[] | null;\n /** Keys of the board migrations applied to the project; null before the first one. */\n applied_migrations: string[] | null;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\ninterface IntakeRouteRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n name: string;\n enabled: boolean;\n position: number;\n when_condition: RuleGroup | null;\n board_key: string;\n phase_key: string | null;\n /** Null on rows written before routes named events: they place new cards. */\n on_events: RouteEvent[] | null;\n join_closed_issue: boolean | null;\n /** Null on rows written before `pull_request.opened` filed pull requests: there it only moves a card. */\n opened_files_pull_requests?: boolean | null;\n /** Null on rows written before rules decided outsiders' pull requests: their card moves skip them. Written since: true restores that gate, false (every new route) lets them match. */\n outsider_pull_requests_gated?: boolean | null;\n move_to_board_key: string | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface IntakeRouteLockRow extends Record<string, unknown> {\n /** Keys of the `DEFAULT_INTAKE_ROUTES` added to the project; null on rows written before the list. */\n seeded_defaults: string[] | null;\n intake_order: string[] | null;\n /** Null while derived. */\n intake_order_origin: 'explicit' | null;\n /** Null on projects created before the setting: they use `route-list`. */\n intake_evaluator?: IntakeEvaluator | null;\n}\n\ninterface IntakeDecisionRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n idempotency_key: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n board_key: string | null;\n route_id: string | null;\n reason: string | null;\n source_key: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decided_at: Date;\n resolved_at: Date | null;\n resolved_by: string | null;\n}\n\nfunction toIntakeDecisionRecord(row: IntakeDecisionRow): StoredIntakeDecisionRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n idempotencyKey: row.idempotency_key,\n outcome: row.outcome,\n evaluator: row.evaluator,\n boardKey: row.board_key,\n routeId: row.route_id,\n reason: row.reason,\n sourceKey: row.source_key,\n title: row.title,\n url: row.url,\n arrival: row.arrival,\n decidedAt: row.decided_at,\n resolvedAt: row.resolved_at,\n resolvedBy: row.resolved_by,\n };\n}\n\nfunction seededDefaults(lock: IntakeRouteLockRow): string[] {\n return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;\n}\n\nfunction missingDefaults(lock: IntakeRouteLockRow): (typeof DEFAULT_INTAKE_ROUTES)[number][] {\n const seeded = new Set(seededDefaults(lock));\n return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst INTAKE_ROUTES = 'factory_intake_routes';\nconst INTAKE_ROUTE_LOCKS = 'factory_intake_route_locks';\nconst INTAKE_DECISIONS = 'factory_intake_decisions';\nconst MAX_WRITE_ATTEMPTS = 3;\nconst MIGRATION_ACTOR = 'factory';\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: currentRuleGroup(row.auto_start_when),\n exitTool: row.exit_tool?.autoApproveWhen\n ? { ...row.exit_tool, autoApproveWhen: currentRuleGroup(row.exit_tool.autoApproveWhen) }\n : row.exit_tool,\n tools: row.tools ?? null,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** Runs inside a board write's transaction, before the board is written. */\nexport type BoardWriteStep = (ops: FactoryStorageOps) => Promise<void>;\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(INTAKE_DECISIONS, {});\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n await this.ops.deleteMany(INTAKE_ROUTES, {});\n await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n return readStoredBoard(this.ops, scope, key);\n }\n\n /**\n * Creates a board through the API. `before` runs in the same transaction, once the key is known\n * to be free. A row under the key that `over` accepts does not hold it: the board is written\n * over that row.\n */\n async create(\n scope: StoredBoardScope,\n input: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n over?: (row: StoredBoardRecord) => boolean,\n ): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const taken = rows.find(row => row.board_key === input.key);\n const stored = taken && over ? await readStoredBoard(ops, scope, input.key) : null;\n if (taken && !(stored && over?.(stored))) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await before?.(ops);\n if (taken) await writeBoard(ops, scope, taken, input, actor);\n else await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string; before?: BoardWriteStep },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await options.before?.(ops);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Stores Factory's boards (Work, app and seed boards) in the project, each key once: a key the\n * project has had before is skipped even if its board was deleted since, and a stored board is\n * never rewritten. A project stored before the list was kept counts the boards it has as stored.\n * Reads one row when every key was stored before. Returns the keys it inserted.\n *\n * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that\n * already has any board, such as one an app stored under that key, is left as it is. The key\n * is still recorded as stored, so it never goes in later, even after the project's boards are\n * deleted: that project chose its boards, and Work is never added beside or after them. The\n * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so\n * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded\n * as the inserted boards' creator. `before` runs in the same\n * transaction ahead of each board it inserts.\n */\n async seedBoards(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor?: string;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n } = {},\n ): Promise<string[]> {\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.seeded_boards && boards.every(board => marker.seeded_boards!.includes(board.key))) return [];\n return this.#insertOnce(scope, boards, {\n actor: options.actor ?? DEFAULT_INTAKE_ROUTE_ACTOR,\n skipSeeded: true,\n onlyIntoEmpty: options.onlyIntoEmpty ?? [],\n intoEmpty: options.intoEmpty ?? [],\n before: options.before,\n });\n }\n\n /** The keys of the boards Factory stored in the project; null before it kept the list. */\n async seededBoardKeys(scope: StoredBoardScope): Promise<string[] | null> {\n return (await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))?.seeded_boards ?? null;\n }\n\n /**\n * Rewrites the board stored under `seed.key` to `seed` at its next revision when `when` says the\n * row is nobody's: one an earlier release seeded for a board Factory no longer has, under a key\n * the app now defines. `before` runs in the same transaction. Returns whether it rewrote the row.\n */\n async adoptSeed(\n scope: StoredBoardScope,\n seed: StoredBoardInput,\n options: { when: (row: StoredBoardRecord) => boolean; before?: BoardWriteStep },\n ): Promise<boolean> {\n return this.#write(scope, async ops => {\n const stored = await readStoredBoard(ops, scope, seed.key);\n if (!stored || !options.when(stored)) return { result: false, changed: false };\n await options.before?.(ops);\n await writeBoard(ops, scope, await findBoard(ops, scope, seed.key), seed, DEFAULT_INTAKE_ROUTE_ACTOR);\n return { result: true, changed: true };\n });\n }\n\n /**\n * Inserts a board into the project unless one is stored under its key, and records the key as\n * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.\n * Returns whether it inserted the board. `before` runs in the same transaction when it does.\n */\n async insertIfMissing(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n ): Promise<boolean> {\n return (await this.#insertOnce(scope, [board], { actor, skipSeeded: false, before })).length > 0;\n }\n\n async #insertOnce(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor: string;\n skipSeeded: boolean;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n },\n ): Promise<string[]> {\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const marker = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const present = new Set(rows.map(row => row.board_key));\n const seeded = new Set(marker.seeded_boards ?? present);\n // The `intoEmpty` boards go into a project with no boards, first; `onlyIntoEmpty` keys then\n // go in only when nothing is stored yet, so a project holding them gets no default beside them.\n const candidates = [...(rows.length === 0 ? (options.intoEmpty ?? []) : []), ...boards];\n let position = nextPosition(rows);\n const inserted: string[] = [];\n for (const board of candidates) {\n if (present.has(board.key) || (options.skipSeeded && seeded.has(board.key))) continue;\n if (present.size > 0 && options.onlyIntoEmpty?.includes(board.key)) continue;\n await options.before?.(ops, board.key);\n await insertBoard(ops, scope, board, { position: position++, actor: options.actor });\n present.add(board.key);\n inserted.push(board.key);\n }\n const next = [...new Set([...seeded, ...candidates.map(board => board.key)])];\n const unchanged = marker.seeded_boards !== null && next.length === marker.seeded_boards.length;\n if (inserted.length === 0 && unchanged) return inserted;\n // Compare-and-set on the version, and every marker write takes a new one: two replicas\n // recording different keys can't both match the version they read, so neither key is lost.\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: marker.version },\n {\n seeded_boards: next,\n version: randomUUID(),\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return inserted;\n });\n }\n\n /**\n * Runs each migration the project hasn't had yet, once: the keys applied are recorded on the\n * project's version row in the same transaction as the board writes, and the compare-and-set on\n * its version makes a concurrent first load retry from fresh reads, where it finds them applied.\n * A migration whose board the project doesn't have is recorded without running, and the version\n * only changes when a board was rewritten. Reads one row\n * when every key was applied before. Returns what each migration that rewrote a board filled.\n */\n async applyBoardMigrations(\n scope: StoredBoardScope,\n migrations: readonly StoredBoardMigration[],\n /**\n * Read through the transaction's `ops`, again on every retry, and only when a migration is still\n * pending, so what it reports is as fresh as the boards the migrations rewrite.\n */\n context: (ops: FactoryStorageOps) => Promise<BoardMigrationContext> = async () => EMPTY_MIGRATION_CONTEXT,\n ): Promise<AppliedBoardMigration[]> {\n if (migrations.length === 0) return [];\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.applied_migrations && migrations.every(({ key }) => marker.applied_migrations!.includes(key))) {\n return [];\n }\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const current = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const applied = current.applied_migrations ?? [];\n const pending = migrations.filter(({ key }) => !applied.includes(key));\n if (pending.length === 0) return [];\n const project = await context(ops);\n const changed: AppliedBoardMigration[] = [];\n for (const migration of pending) {\n const rows =\n migration.boardKey === null\n ? await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))\n : await ops.findMany<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: migration.boardKey });\n for (const row of rows) {\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n const result = migration.migrate(toRecord(row, phases), project);\n if (!result) continue;\n await writeBoard(ops, scope, row, { ...result.board, key: row.board_key }, MIGRATION_ACTOR);\n changed.push({ key: migration.key, boardKey: row.board_key, filled: result.filled });\n }\n }\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: current.version },\n {\n applied_migrations: [...applied, ...pending.map(({ key }) => key)],\n // Only a rewritten board is news to the other replicas' caches.\n version: changed.length > 0 ? randomUUID() : current.version,\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return changed;\n });\n }\n\n /** Rewrites a board to `definition` (Factory's current one for its key), raising its revision. */\n async resetTo(\n scope: StoredBoardScope,\n key: string,\n definition: StoredBoardInput,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { ...definition, key }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Deletes a board, its phases and its intake routes in one transaction, and takes it out of the\n * intake order. Returns the routes it deleted, for the caller to audit.\n */\n async delete(\n scope: StoredBoardScope,\n key: string,\n options: { expectedRevision: number },\n ): Promise<{ intakeRoutes: StoredIntakeRouteRecord[] }> {\n await this.#ensureIntakeRoutes(scope);\n return this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n const routes = await lockIntakeRoutes(ops, scope);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n const deleted = routes.filter(route => route.board_key === key);\n if (deleted.length > 0) {\n // The surviving routes keep their positions; readers sort over the gaps.\n await ops.deleteMany(INTAKE_ROUTES, { ...scopeWhere(scope), board_key: key });\n await forgetDerivedIntakeOrder(ops, scope);\n }\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n if (lock.intake_order?.includes(key)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: lock.intake_order.filter(other => other !== key),\n });\n }\n return { result: { intakeRoutes: deleted.map(toIntakeRouteRecord) }, changed: true };\n });\n }\n\n /**\n * The project's intake routes in the order they are tried, or one board's list when `boardKey`\n * is set; Factory's `DEFAULT_INTAKE_ROUTES` are added once each.\n */\n async listIntakeRoutes(\n scope: StoredBoardScope,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n const rows = await readIntakeRoutes(this.ops, scope);\n return rows\n .filter(row => options.boardKey === undefined || row.board_key === options.boardKey)\n .map(toIntakeRouteRecord);\n }\n\n /**\n * The project's intake order, derived from the route list the first time it is read and kept up\n * to date with its boards (see `reconcileIntakeOrder`), with the migration marker. Its boards are\n * the stored ones plus `options.boards` (the caller's registry, so a code board keeps its place).\n */\n async readIntakeOrder(\n scope: StoredBoardScope,\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n const current = await this.#intakeOrderState(this.ops, scope, options.boards);\n if (current.lock.intake_order && sameKeys(current.lock.intake_order, current.boardKeys)) {\n return toIntakeOrder(current.lock, current.boardKeys);\n }\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const fresh = await this.#intakeOrderState(ops, scope, options.boards);\n if (!fresh.lock.intake_order || !sameKeys(fresh.lock.intake_order, fresh.boardKeys)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_order: fresh.boardKeys });\n }\n return toIntakeOrder(fresh.lock, fresh.boardKeys);\n });\n }\n\n /**\n * Sets the project's intake order, which then no longer follows the route list; `boardKeys` must\n * name every board of the project exactly once: its stored boards, or `options.boards` when given\n * (the caller's registry, code boards too).\n */\n async setIntakeOrder(\n scope: StoredBoardScope,\n boardKeys: string[],\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const keys = new Set(\n options.boards ?? (await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))).map(board => board.board_key),\n );\n if (\n boardKeys.length !== keys.size ||\n new Set(boardKeys).size !== boardKeys.length ||\n boardKeys.some(key => !keys.has(key))\n ) {\n throw new StoredBoardError(\n 'intake_order_set_mismatch',\n 'The intake order must list every board of the project exactly once; reload the boards and try again.',\n );\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: boardKeys,\n intake_order_origin: 'explicit',\n });\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n return toIntakeOrder(lock, boardKeys);\n });\n }\n\n /** The project's own evaluator; null for a project created before the setting, which uses `route-list`. */\n async intakeEvaluator(scope: StoredBoardScope): Promise<IntakeEvaluator | null> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n return lock?.intake_evaluator ?? null;\n }\n\n /** Switches the project's evaluator; returns the setting it had (null: none). */\n async setIntakeEvaluator(scope: StoredBoardScope, evaluator: IntakeEvaluator): Promise<IntakeEvaluator | null> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_evaluator: evaluator });\n return lock.intake_evaluator ?? null;\n });\n }\n\n /** Records how intake decided an arrival; a redelivery under the same key replaces the row. */\n async recordIntakeDecision(\n scope: StoredBoardScope,\n input: IntakeDecisionInput,\n now = new Date(),\n ): Promise<StoredIntakeDecisionRecord> {\n const row = await this.ops.upsertOne<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n ['org_id', 'factory_project_id', 'idempotency_key'],\n {\n ...scopeWhere(scope),\n idempotency_key: input.idempotencyKey,\n outcome: input.outcome,\n evaluator: input.evaluator,\n board_key: input.boardKey ?? null,\n route_id: input.routeId ?? null,\n reason: input.reason ?? null,\n source_key: input.sourceKey ?? null,\n title: input.title,\n url: input.url ?? null,\n arrival: input.arrival ?? null,\n decided_at: now,\n resolved_at: null,\n resolved_by: null,\n },\n );\n return toIntakeDecisionRecord(row);\n }\n\n async getIntakeDecision(scope: StoredBoardScope, id: string): Promise<StoredIntakeDecisionRecord | null> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, { ...scopeWhere(scope), id });\n return row ? toIntakeDecisionRecord(row) : null;\n }\n\n /**\n * Items no board took and nobody has filed since, oldest first, `limit` at a time; pass\n * `nextCursor` back as `cursor` for the next page.\n */\n async listNotRouted(\n scope: StoredBoardScope,\n options: { limit?: number; cursor?: string } = {},\n ): Promise<{ notRouted: StoredIntakeDecisionRecord[]; nextCursor: string | null }> {\n const limit = options.limit ?? 50;\n const after = options.cursor === undefined ? undefined : decodeDecisionCursor(options.cursor);\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n {\n orderBy: DECISION_ORDER,\n limit: limit + 1,\n ...(after && { cursor: { values: [after.decidedAt, after.id] } }),\n },\n );\n const page = rows.slice(0, limit).map(toIntakeDecisionRecord);\n const last = page.at(-1);\n return {\n notRouted: page,\n nextCursor: rows.length > limit && last ? `${last.decidedAt.toISOString()}_${last.id}` : null,\n };\n }\n\n /** Whether intake turned the source away (Not routed) and nobody has filed it since. */\n async isNotRouted(scope: StoredBoardScope, sourceKey: string): Promise<boolean> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, {\n ...scopeWhere(scope),\n outcome: 'not_routed',\n source_key: sourceKey,\n resolved_at: null,\n });\n return row !== null;\n }\n\n /** The newest `limit` items no board took and nobody has filed since, newest first. */\n async listRecentNotRouted(scope: StoredBoardScope, limit: number): Promise<StoredIntakeDecisionRecord[]> {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n { orderBy: NEWEST_DECISION_ORDER, limit },\n );\n return rows.map(toIntakeDecisionRecord);\n }\n\n /**\n * How many items each intake rule placed since `since`, keyed by rule id. Reads placed rows\n * newest first, a page at a time, and stops at the first one older than `since`.\n */\n async countPlacedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, number>> {\n const pageSize = options.pageSize ?? 500;\n const counts: Record<string, number> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'placed' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return counts;\n if (row.route_id) counts[row.route_id] = (counts[row.route_id] ?? 0) + 1;\n }\n if (rows.length < pageSize) return counts;\n cursor = rows.at(-1);\n }\n }\n\n /**\n * How often each card-move rule was skipped since `since`, with its newest skip, keyed by rule id.\n * Reads skipped rows newest first, a page at a time, and stops at the first one older than `since`.\n */\n async summarizeSkippedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, { count: number; latest: StoredIntakeDecisionRecord }>> {\n const pageSize = options.pageSize ?? 500;\n const summary: Record<string, { count: number; latest: StoredIntakeDecisionRecord }> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'rule_skipped' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return summary;\n if (!row.route_id) continue;\n const seen = summary[row.route_id];\n if (seen) seen.count += 1;\n else summary[row.route_id] = { count: 1, latest: toIntakeDecisionRecord(row) };\n }\n if (rows.length < pageSize) return summary;\n cursor = rows.at(-1);\n }\n }\n\n /** Marks the Not routed rows for a source resolved once a card is filed for it. Returns how many. */\n async resolveNotRouted(scope: StoredBoardScope, sourceKey: string, by: string, now = new Date()): Promise<number> {\n return this.ops.updateMany(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', source_key: sourceKey, resolved_at: null },\n { resolved_at: now, resolved_by: by },\n );\n }\n\n async #intakeOrderState(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n extra: readonly string[] = [],\n ): Promise<{ lock: IntakeRouteLockRow; boardKeys: string[] }> {\n const [lock, boards, routes] = await Promise.all([\n ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)),\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n readIntakeRoutes(ops, scope),\n ]);\n const sidebar = boards\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(board => board.board_key);\n sidebar.push(...extra.filter(key => !sidebar.includes(key)));\n const records = routes.map(toIntakeRouteRecord);\n const stored = lock!.intake_order ?? deriveIntakeOrder(records, sidebar);\n return { lock: lock!, boardKeys: reconcileIntakeOrder(stored, sidebar, records) };\n }\n\n async getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null> {\n const row = await this.ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n return row ? toIntakeRouteRecord(row) : null;\n }\n\n /**\n * Adds a route after the project's last one. A route that places new cards goes just ahead of the\n * first route that takes every new card instead, since after it it would never place one.\n */\n async createIntakeRoute(\n scope: StoredBoardScope,\n input: StoredIntakeRouteInput,\n actor: string,\n ): Promise<StoredIntakeRouteRecord> {\n const id = randomUUID();\n checkRouteEvents(input.on ?? DEFAULT_ROUTE_EVENTS, input.when ?? null);\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n if (boardRouteCount(rows, input.target.boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n const position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n await insertIntakeRoute(ops, scope, { id, input, position, actor });\n await forgetDerivedIntakeOrder(ops, scope);\n // Ahead of the catch-all taking each kind it files, the later one when they differ, so a route\n // filing issues and pull requests stays behind a catch-all for pull requests, as it always\n // has. A kind no route catches reaches it at the end, so it stays there.\n const catchAlls = [\n ...arrivalKinds({\n on: input.on ?? DEFAULT_ROUTE_EVENTS,\n ...(input.pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true }),\n }),\n ].map(kind => rows.findIndex(row => catchesEveryNewCard(row, kind)));\n const ahead = catchAlls.length > 0 && !catchAlls.includes(-1) ? Math.max(...catchAlls) : -1;\n if (ahead >= 0) {\n const added = (await readIntakeRoutes(ops, scope)).find(row => row.id === id)!;\n const target = rows[ahead]!;\n const previous = ahead === 0 ? -1 : rows[ahead - 1]!.position;\n if (target.position - previous > 1) {\n // A deleted route left a free slot just ahead of the catch-all: take it and move nothing.\n await updateIntakeRouteRow(ops, added, { position: target.position - 1 });\n } else {\n // Move the catch-all and what follows it one place down; the routes ahead stay put.\n await moveIntakeRoutes(\n ops,\n [added, ...rows.slice(ahead)].map((row, index) => ({ row, position: target.position + index })),\n actor,\n );\n }\n }\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Changes the fields `patch` names; the route keeps its place in the order. */\n async updateIntakeRoute(\n scope: StoredBoardScope,\n id: string,\n patch: Partial<StoredIntakeRouteInput>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredIntakeRouteRecord> {\n await this.#transact(async ops => {\n // Lock first, as every route write does, so it can't deadlock against a reorder.\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n const boardKey = patch.target?.boardKey;\n if (\n boardKey !== undefined &&\n boardKey !== row.board_key &&\n boardRouteCount(rows, boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD\n ) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n checkRouteEvents(patch.on ?? routeEvents(row), patch.when !== undefined ? patch.when : row.when_condition);\n await updateIntakeRouteRow(ops, row, {\n ...(patch.on !== undefined && { on_events: patch.on }),\n ...(patch.name !== undefined && { name: patch.name }),\n ...(patch.enabled !== undefined && { enabled: patch.enabled }),\n ...(patch.when !== undefined && { when_condition: patch.when }),\n // Only an explicit `false` lets outsiders' pull requests match: no other edit, Undo\n // included, may quietly widen an older rule onto outside authors' pull requests.\n ...(patch.outsiderPullRequestsGated === false && { outsider_pull_requests_gated: false }),\n ...(patch.target !== undefined && {\n board_key: patch.target.boardKey,\n phase_key: patch.target.phaseKey ?? null,\n join_closed_issue: patch.target.joinClosedIssue ?? false,\n move_to_board_key: patch.target.moveToBoardKey ?? null,\n }),\n updated_by: options.actor,\n });\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Deletes a route; the others keep their positions, and readers sort over the gap. */\n async deleteIntakeRoute(scope: StoredBoardScope, id: string, options: { expectedRevision: number }): Promise<void> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n if ((await ops.deleteMany(INTAKE_ROUTES, { id: row.id, revision: row.revision })) === 0) {\n throw new ConcurrentBoardWrite();\n }\n await forgetDerivedIntakeOrder(ops, scope);\n });\n }\n\n /**\n * Puts the project's routes in the order of `ids`, which must name every route exactly once. With\n * `boardKey`, `ids` names every route of that board instead: they trade the places the board's\n * routes hold, and every other board's routes keep theirs. Returns the routes reordered.\n */\n async reorderIntakeRoutes(\n scope: StoredBoardScope,\n ids: string[],\n actor: string,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n const { boardKey } = options;\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const scoped = boardKey === undefined ? rows : rows.filter(row => row.board_key === boardKey);\n const byId = new Map(scoped.map(row => [row.id, row]));\n if (ids.length !== scoped.length || new Set(ids).size !== ids.length || ids.some(id => !byId.has(id))) {\n throw new StoredBoardError(\n 'intake_route_set_mismatch',\n boardKey === undefined\n ? 'The order must list every intake route of the project exactly once; reload the routes and try again.'\n : `The order must list every intake rule of board \"${boardKey}\" exactly once; reload the rules and try again.`,\n );\n }\n const queue = ids.map(id => byId.get(id)!);\n if (boardKey === undefined) {\n await placeIntakeRoutes(ops, queue, actor);\n } else {\n // The board's routes trade the position slots the board already holds, so every other\n // board's routes keep their positions and revisions.\n const slots = scoped.map(row => row.position);\n await moveIntakeRoutes(\n ops,\n queue.map((row, index) => ({ row, position: slots[index]! })),\n actor,\n );\n }\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return this.listIntakeRoutes(scope, { boardKey });\n }\n\n /**\n * Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of\n * `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row\n * records every default it added, so a project whose admin deleted one doesn't get it back. Runs\n * before, never inside, a write's transaction: the lock taken there must always be an update.\n */\n async #ensureIntakeRoutes(scope: StoredBoardScope): Promise<void> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n if (lock && missingDefaults(lock).length === 0) return;\n await this.#transact(async ops => {\n if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);\n // A racing first read inserted the lock row first: this one fails on the unique index and\n // retries, taking the lock above.\n else\n await ops.insertOne(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), locked_at: new Date(), seeded_defaults: [] });\n // Read under the lock: a racing seeder that committed first already added what it listed.\n const current = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n const missing = missingDefaults(current);\n if (missing.length === 0) return;\n const rows = await readIntakeRoutes(ops, scope);\n const retired = new Set<string>();\n // Pull requests link to the card of the issue they close on their own now: a route that\n // joined them is switched off, and kept so its history stays readable.\n // One an admin had changed is named in the decision log: the linked rule doesn't do all it did.\n if (missing.some(({ key }) => key === LINKED_PULL_REQUEST_ROUTE_KEY)) {\n for (const row of rows) {\n if (!row.join_closed_issue || !row.enabled) continue;\n await updateIntakeRouteRow(ops, row, { enabled: false, updated_by: DEFAULT_INTAKE_ROUTE_ACTOR });\n retired.add(row.id);\n if (isShippedJoinRoute(row)) continue;\n await ops.upsertOne(INTAKE_DECISIONS, ['org_id', 'factory_project_id', 'idempotency_key'], {\n ...scopeWhere(scope),\n idempotency_key: `rule-retired:${row.id}`,\n outcome: 'rule_retired',\n evaluator: current.intake_evaluator ?? 'route-list',\n board_key: row.board_key,\n route_id: row.id,\n reason:\n 'Switched off: pull requests now link to the card of the issue they close on their own, and only the rule `Trusted pull requests take a waiting issue to Review` moves a waiting card. Add a card-move rule on pull_request.opened to move cards the way this route did.',\n source_key: null,\n title: row.name,\n url: null,\n arrival: null,\n decided_at: new Date(),\n resolved_at: null,\n resolved_by: null,\n });\n }\n }\n let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n const first: string[] = [];\n const perBoard = new Map<string, number>();\n // Only a project no default was added to yet is new.\n const newProject = seededDefaults(current).length === 0;\n for (const { key, route, first: leads, newProjectsOnly } of missing) {\n if (newProjectsOnly && !newProject) continue;\n // A board at the limit keeps its own routes; the default counts as added all the same. The\n // linked rule takes the slot of a join route it switched off.\n const count =\n perBoard.get(route.target.boardKey) ??\n boardRouteCount(\n key === LINKED_PULL_REQUEST_ROUTE_KEY ? rows.filter(row => !retired.has(row.id)) : rows,\n route.target.boardKey,\n );\n if (count >= MAX_INTAKE_ROUTES_PER_BOARD) continue;\n perBoard.set(route.target.boardKey, count + 1);\n const id = randomUUID();\n await insertIntakeRoute(ops, scope, {\n id,\n input: route,\n position: position++,\n actor: DEFAULT_INTAKE_ROUTE_ACTOR,\n });\n if (leads) first.push(id);\n }\n // A project that had routes before gets a leading default ahead of them.\n if (first.length > 0 && rows.length > 0) {\n const placed = await readIntakeRoutes(ops, scope);\n const leading = new Set(first);\n await placeIntakeRoutes(ops, [\n ...first.map(id => placed.find(row => row.id === id)!),\n ...placed.filter(row => !leading.has(row.id)),\n ]);\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)],\n });\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n return this.#transact(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n }\n\n /**\n * Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it\n * directly: routes are read uncached, so they leave the board definition version alone.\n */\n async #transact<T>(fn: (ops: FactoryStorageOps) => Promise<T>): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(fn);\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\n/** The project's board under `key`, read through `ops` so a caller inside a transaction reads within it. */\nexport async function readStoredBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n key: string,\n): Promise<StoredBoardRecord | null> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n tools: phase.tools?.length ? phase.tools : null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n\n/**\n * A row's events as stored. One written before routes named events has none: it reads as the legacy\n * `work_item.created`, filing issues and pull requests alike, as it always has (rows are never rewritten).\n */\nfunction routeEvents(row: IntakeRouteRow): RouteEvent[] {\n return row.on_events ? [...row.on_events] : [...DEFAULT_ROUTE_EVENTS];\n}\n\n/** A row's events with what they mean on it: `pull_request.opened` only moves a card on a row from before it filed. */\nfunction routeArrivals(row: IntakeRouteRow): RouteArrivals {\n const on = routeEvents(row);\n return {\n on,\n pullRequestOpenedMovesOnly: row.opened_files_pull_requests !== true && on.includes('pull_request.opened'),\n };\n}\n\nfunction checkRouteEvents(on: readonly string[], when: RuleGroup | null): void {\n const problem = routeEventsProblem(on, when);\n if (problem) throw new StoredBoardError('invalid_intake_route', problem);\n}\n\nfunction toIntakeRouteRecord(row: IntakeRouteRow): StoredIntakeRouteRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n name: row.name,\n enabled: row.enabled,\n position: row.position,\n when: currentRuleGroup(row.when_condition),\n target: {\n boardKey: row.board_key,\n phaseKey: row.phase_key,\n joinClosedIssue: row.join_closed_issue === true,\n moveToBoardKey: row.move_to_board_key ?? null,\n },\n on: routeEvents(row),\n ...(routeArrivals(row).pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true as const }),\n ...(row.outsider_pull_requests_gated !== false && { outsiderPullRequestsGated: true as const }),\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\nconst DECISION_ORDER: [string, 'asc'][] = [\n ['decided_at', 'asc'],\n ['id', 'asc'],\n];\nconst NEWEST_DECISION_ORDER: [string, 'desc'][] = [\n ['decided_at', 'desc'],\n ['id', 'desc'],\n];\n\nfunction decodeDecisionCursor(cursor: string): { decidedAt: Date; id: string } {\n const sep = cursor.lastIndexOf('_');\n const decidedAt = new Date(cursor.slice(0, sep));\n const id = cursor.slice(sep + 1);\n if (sep <= 0 || Number.isNaN(decidedAt.getTime()) || !id) {\n throw new StoredBoardError('invalid_intake_cursor', 'The cursor is not one this list returned.');\n }\n return { decidedAt, id };\n}\n\n/**\n * Stamps a project being created with the `intake-order` evaluator, through `ops`, the creating\n * transaction's, so the project and its setting commit together. A new project has no lock row yet;\n * its first intake read adds the default routes to this one. Its intake order is its own from the\n * start (`explicit`, empty): deriving one from the route list is for projects that had one before,\n * and would keep Work, whose defaults lead the list, ahead of every board added later. Each board\n * slots in as it comes, just above the first board that takes every new card.\n */\nexport async function stampNewProjectIntake(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.insertOne(INTAKE_ROUTE_LOCKS, {\n ...scopeWhere(scope),\n locked_at: new Date(),\n seeded_defaults: [],\n intake_order: [],\n intake_order_origin: 'explicit',\n intake_evaluator: 'intake-order',\n });\n}\n\nfunction toIntakeOrder(lock: IntakeRouteLockRow, boardKeys: string[]): StoredIntakeOrder {\n return { boardKeys, origin: lock.intake_order_origin ?? 'derived' };\n}\n\n/**\n * A rule write changes what a derived order would be: drop it, so the next read derives it afresh.\n * An order an admin set stays.\n */\nasync function forgetDerivedIntakeOrder(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), intake_order_origin: null }, { intake_order: null });\n}\n\nfunction sameKeys(left: readonly string[], right: readonly string[]): boolean {\n return left.length === right.length && left.every((key, index) => key === right[index]);\n}\n\nfunction boardRouteCount(rows: readonly IntakeRouteRow[], boardKey: string): number {\n return rows.filter(row => row.board_key === boardKey).length;\n}\n\n/** Whether a stored join route is still the one projects were given, which the linked rule replaces. */\nfunction isShippedJoinRoute(row: IntakeRouteRow): boolean {\n return (\n row.board_key === RETIRED_JOIN_ROUTE.target.boardKey &&\n row.phase_key === RETIRED_JOIN_ROUTE.target.phaseKey &&\n isDeepStrictEqual(currentRuleGroup(row.when_condition), RETIRED_JOIN_ROUTE.when)\n );\n}\n\n/** Whether `row` files every new issue, or pull request, that reaches it, as the seeded \"Everything else\" route does. */\nfunction catchesEveryNewCard(row: IntakeRouteRow, kind: ArrivalKind): boolean {\n return (\n row.enabled &&\n !row.join_closed_issue &&\n kindsTakenWhole({ when: row.when_condition, ...routeArrivals(row) }).includes(kind)\n );\n}\n\nasync function readIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n const rows = await ops.findMany<IntakeRouteRow>(INTAKE_ROUTES, scopeWhere(scope));\n return rows.sort((left, right) => left.position - right.position);\n}\n\nfunction intakeRouteNotFound(id: string): StoredBoardError {\n return new StoredBoardError('intake_route_not_found', `Intake route \"${id}\" does not exist in this project.`);\n}\n\nfunction checkIntakeRouteRevision(row: IntakeRouteRow, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Intake route \"${row.name}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\n/** Sets columns on a route row and raises its revision, unless another writer changed it first. */\nasync function updateIntakeRouteRow(\n ops: FactoryStorageOps,\n row: IntakeRouteRow,\n set: Partial<IntakeRouteRow>,\n): Promise<number> {\n const revision = row.revision + 1;\n const updated = await ops.updateMany(\n INTAKE_ROUTES,\n { id: row.id, revision: row.revision },\n { ...set, revision, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return revision;\n}\n\nasync function insertIntakeRoute(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n route: { id: string; input: StoredIntakeRouteInput; position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<IntakeRouteRow>(INTAKE_ROUTES, {\n id: route.id,\n ...scopeWhere(scope),\n name: route.input.name,\n enabled: route.input.enabled ?? true,\n position: route.position,\n when_condition: route.input.when ?? null,\n board_key: route.input.target.boardKey,\n phase_key: route.input.target.phaseKey ?? null,\n on_events: route.input.on ?? null,\n join_closed_issue: route.input.target.joinClosedIssue ?? false,\n opened_files_pull_requests: route.input.pullRequestOpenedMovesOnly ? null : true,\n outsider_pull_requests_gated: route.input.outsiderPullRequestsGated === true,\n move_to_board_key: route.input.target.moveToBoardKey ?? null,\n revision: 1,\n created_by: route.actor,\n created_at: now,\n updated_by: route.actor,\n updated_at: now,\n });\n}\n\n/**\n * Takes the project's route lock and reads the routes. Writes that add, delete or move routes\n * call this first, so they run one after another and each reads what the one before committed.\n */\nasync function lockIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n if ((await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: new Date() })) !== 1) {\n throw new ConcurrentBoardWrite();\n }\n return readIntakeRoutes(ops, scope);\n}\n\n/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */\nasync function placeIntakeRoutes(ops: FactoryStorageOps, rows: IntakeRouteRow[], actor?: string): Promise<void> {\n await moveIntakeRoutes(\n ops,\n rows.map((row, position) => ({ row, position })),\n actor,\n );\n}\n\n/**\n * Moves each route of `moves`, read under the project's route lock, to the position named for it.\n * A route already in its place is left alone. Each move parks at a negative position first, so the\n * moves can trade places without meeting the unique position index on the way.\n */\nasync function moveIntakeRoutes(\n ops: FactoryStorageOps,\n moves: { row: IntakeRouteRow; position: number }[],\n actor?: string,\n): Promise<void> {\n const moving = moves.filter(({ row, position }) => row.position !== position);\n const parked = [];\n for (const [index, { row, position }] of moving.entries()) {\n const revision = await updateIntakeRouteRow(ops, row, {\n position: -(index + 1),\n ...(actor !== undefined && { updated_by: actor }),\n });\n parked.push({ id: row.id, revision, position });\n }\n for (const { id, revision, position } of parked) {\n if ((await ops.updateMany(INTAKE_ROUTES, { id, revision }, { position })) !== 1) throw new ConcurrentBoardWrite();\n }\n}\n"],"mappings":";;;;;;;;;AAmIA,MAAM,0BAAiD;CACrD,iBAAiB;CACjB,gCAAgB,IAAI,IAAI;CACxB,kBAAkB,KAAA;CAClB,YAAY,CAAC;AACf;;AA6FA,MAAa,8BAA8B;;AAgF3C,MAAM,wBAAwB,CAAC,iBAAiB;;AAGhD,MAAa,6BAA6B;AAE1C,IAAa,mBAAb,cAAsC,MAAM;CAG/B;CAFX,OAAgB;CAChB,YACE,MACA,SACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;CAIX;AACF;AAiGA,SAAS,uBAAuB,KAAoD;CAClF,OAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,kBAAkB,IAAI;EACtB,gBAAgB,IAAI;EACpB,SAAS,IAAI;EACb,WAAW,IAAI;EACf,UAAU,IAAI;EACd,SAAS,IAAI;EACb,QAAQ,IAAI;EACZ,WAAW,IAAI;EACf,OAAO,IAAI;EACX,KAAK,IAAI;EACT,SAAS,IAAI;EACb,WAAW,IAAI;EACf,YAAY,IAAI;EAChB,YAAY,IAAI;CAClB;AACF;AAEA,SAAS,eAAe,MAAoC;CAC1D,OAAO,KAAK,mBAAmB;AACjC;AAEA,SAAS,gBAAgB,MAAoE;CAC3F,MAAM,SAAS,IAAI,IAAI,eAAe,IAAI,CAAC;CAC3C,OAAO,sBAAsB,QAAQ,EAAE,UAAU,CAAC,OAAO,IAAI,GAAG,CAAC;AACnE;AAEA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AAExB,SAAS,WAAW,EAAE,OAAO,oBAAsC;CACjE,OAAO;EAAE,QAAQ;EAAO,oBAAoB;CAAiB;AAC/D;AAEA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