@mastra/factory 0.29.0-alpha.3 → 0.29.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -64
- package/dist/boards/board-events.d.ts +89 -9
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +176 -13
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +14 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/busy-card.d.ts +11 -0
- package/dist/boards/busy-card.d.ts.map +1 -0
- package/dist/boards/busy-card.js +15 -0
- package/dist/boards/busy-card.js.map +1 -0
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +18 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/index.d.ts +2 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +3 -2
- package/dist/boards/intake-dry-run.d.ts +109 -0
- package/dist/boards/intake-dry-run.d.ts.map +1 -0
- package/dist/boards/intake-dry-run.js +158 -0
- package/dist/boards/intake-dry-run.js.map +1 -0
- package/dist/boards/intake-lookup.d.ts +32 -0
- package/dist/boards/intake-lookup.d.ts.map +1 -0
- package/dist/boards/intake-lookup.js +12 -0
- package/dist/boards/intake-lookup.js.map +1 -0
- package/dist/boards/intake-order.d.ts +32 -0
- package/dist/boards/intake-order.d.ts.map +1 -0
- package/dist/boards/intake-order.js +60 -0
- package/dist/boards/intake-order.js.map +1 -0
- package/dist/boards/intake-routing.d.ts +246 -35
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +437 -52
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/reroute.d.ts +7 -3
- package/dist/boards/reroute.d.ts.map +1 -1
- package/dist/boards/reroute.js +21 -4
- package/dist/boards/reroute.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -28
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +7 -39
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-routes.d.ts +31 -11
- package/dist/boards/work-routes.d.ts.map +1 -1
- package/dist/boards/work-routes.js +104 -20
- package/dist/boards/work-routes.js.map +1 -1
- package/dist/factory.d.ts +27 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +32 -18
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/integrations/base.d.ts +9 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +2 -6
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/commits.d.ts +0 -21
- package/dist/integrations/github/commits.d.ts.map +1 -1
- package/dist/integrations/github/commits.js +1 -24
- package/dist/integrations/github/commits.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +22 -1
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +23 -5
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/intake-lookup.d.ts +16 -0
- package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/github/intake-lookup.js +76 -0
- package/dist/integrations/github/intake-lookup.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +20 -6
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +23 -12
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +1 -1
- package/dist/integrations/github/routes.d.ts +1 -11
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +20 -517
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +12 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +275 -38
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +30 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +19 -3
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/discovery.d.ts +1 -1
- package/dist/integrations/gitlab/discovery.js +1 -1
- package/dist/integrations/gitlab/discovery.js.map +1 -1
- package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
- package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/gitlab/intake-lookup.js +85 -0
- package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
- package/dist/integrations/gitlab/integration.d.ts +5 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +21 -2
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts +0 -2
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +49 -165
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +20 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +128 -19
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +5 -5
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +3 -59
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +15 -9
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts +2 -2
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +0 -68
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +13 -7
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -2
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +0 -83
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +14 -7
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +9 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +6 -6
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +23 -6
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/routes.d.ts +2 -2
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +0 -69
- package/dist/integrations/platform/jira/routes.js.map +1 -1
- package/dist/integrations/pull-request-head.d.ts +1 -1
- package/dist/integrations/pull-request-head.d.ts.map +1 -1
- package/dist/integrations/pull-request-head.js +5 -0
- package/dist/integrations/pull-request-head.js.map +1 -1
- package/dist/integrations/vanta/rules.d.ts.map +1 -1
- package/dist/integrations/vanta/rules.js +2 -6
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +0 -2
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +2 -6
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +8 -1
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +33 -7
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +6 -0
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +5 -2
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +1258 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +588 -17
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts +10 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +184 -11
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake-check.d.ts +92 -0
- package/dist/routes/intake-check.d.ts.map +1 -0
- package/dist/routes/intake-check.js +322 -0
- package/dist/routes/intake-check.js.map +1 -0
- package/dist/routes/intake-routes.d.ts +10 -2
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +292 -11
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/mastra-gateway.d.ts.map +1 -1
- package/dist/routes/mastra-gateway.js +3 -2
- package/dist/routes/mastra-gateway.js.map +1 -1
- package/dist/routes/project-sessions.d.ts +49 -0
- package/dist/routes/project-sessions.d.ts.map +1 -0
- package/dist/routes/project-sessions.js +93 -0
- package/dist/routes/project-sessions.js.map +1 -0
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +4 -17
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/run-queue.d.ts +6 -6
- package/dist/routes/run-queue.d.ts.map +1 -1
- package/dist/routes/run-queue.js +28 -8
- package/dist/routes/run-queue.js.map +1 -1
- package/dist/routes/session-rows.d.ts +30 -0
- package/dist/routes/session-rows.d.ts.map +1 -0
- package/dist/routes/session-rows.js +98 -0
- package/dist/routes/session-rows.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +4 -8
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +8 -106
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +13 -3
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +25 -38
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-item-starters.d.ts +1 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -1
- package/dist/routes/work-item-starters.js +14 -2
- package/dist/routes/work-item-starters.js.map +1 -1
- package/dist/routes/work-items.d.ts +13 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +87 -34
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatch-errors.js +1 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +39 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +362 -127
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +69 -1
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +151 -5
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +1 -6
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.js +1 -1
- package/dist/rules/rule-group.d.ts +18 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +52 -8
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/run-bearing.d.ts +8 -0
- package/dist/rules/run-bearing.d.ts.map +1 -0
- package/dist/rules/run-bearing.js +11 -0
- package/dist/rules/run-bearing.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +2 -3
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +27 -35
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.js +2 -1
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +16 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +34 -12
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +18 -5
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/update-fold.d.ts +32 -0
- package/dist/rules/update-fold.d.ts.map +1 -0
- package/dist/rules/update-fold.js +60 -0
- package/dist/rules/update-fold.js.map +1 -0
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +54 -6
- package/dist/rules/validation.js.map +1 -1
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js +2 -3
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/run-audit.d.ts +9 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +9 -1
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +26 -2
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +60 -10
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-row-query.d.ts +25 -0
- package/dist/session/session-row-query.d.ts.map +1 -0
- package/dist/session/session-row-query.js +47 -0
- package/dist/session/session-row-query.js.map +1 -0
- package/dist/session/session-row-status.d.ts +16 -0
- package/dist/session/session-row-status.d.ts.map +1 -0
- package/dist/session/session-row-status.js +14 -0
- package/dist/session/session-row-status.js.map +1 -0
- package/dist/session/session-row-view.d.ts +14 -0
- package/dist/session/session-row-view.d.ts.map +1 -0
- package/dist/session/session-row-view.js +125 -0
- package/dist/session/session-row-view.js.map +1 -0
- package/dist/session/session-rows.d.ts +46 -0
- package/dist/session/session-rows.d.ts.map +1 -0
- package/dist/session/session-rows.js +232 -0
- package/dist/session/session-rows.js.map +1 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +1 -0
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/source-control-tools.d.ts +14 -7
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +10 -2
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +44 -0
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +80 -1
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/session/work-item-state-processor.d.ts.map +1 -1
- package/dist/session/work-item-state-processor.js +44 -8
- package/dist/session/work-item-state-processor.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +3 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +162 -14
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +415 -41
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts +6 -0
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +93 -3
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +11 -10
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +30 -65
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +0 -2
- package/dist/storage/domains/integrations/base.d.ts.map +1 -1
- package/dist/storage/domains/integrations/base.js +0 -6
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +19 -22
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +0 -10
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +6 -21
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +1 -6
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +49 -53
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +152 -156
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +3 -2
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +4 -2
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +12 -3
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +12 -3
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/storage/legacy-collections.d.ts +9 -0
- package/dist/storage/legacy-collections.d.ts.map +1 -0
- package/dist/storage/legacy-collections.js +17 -0
- package/dist/storage/legacy-collections.js.map +1 -0
- package/dist/storage/probed-list.d.ts +11 -0
- package/dist/storage/probed-list.d.ts.map +1 -0
- package/dist/storage/probed-list.js +52 -0
- package/dist/storage/probed-list.js.map +1 -0
- package/dist/tools/audit-events-tool.d.ts +2 -2
- package/dist/tools/read-tools.d.ts +0 -3
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +4 -42
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +5 -9
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +3 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +8 -4
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +4 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +7 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-context-sessions.d.ts +50 -0
- package/dist/work-items/card-context-sessions.d.ts.map +1 -0
- package/dist/work-items/card-context-sessions.js +84 -0
- package/dist/work-items/card-context-sessions.js.map +1 -0
- package/dist/work-items/change-requests.d.ts +87 -0
- package/dist/work-items/change-requests.d.ts.map +1 -0
- package/dist/work-items/change-requests.js +134 -0
- package/dist/work-items/change-requests.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +7 -2
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +44 -13
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts.map +1 -1
- package/dist/work-items/list-related-cards.js +1 -1
- package/dist/work-items/list-related-cards.js.map +1 -1
- package/dist/work-items/providers/github.d.ts.map +1 -1
- package/dist/work-items/providers/github.js +1 -0
- package/dist/work-items/providers/github.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -3
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +5 -3
- package/factory-skills/factory-self-review/SKILL.md +2 -0
- package/factory-skills/factory-triage/SKILL.md +1 -1
- package/package.json +10 -10
- package/dist/session/filesystem-capture.d.ts +0 -50
- package/dist/session/filesystem-capture.d.ts.map +0 -1
- package/dist/session/filesystem-capture.js +0 -229
- package/dist/session/filesystem-capture.js.map +0 -1
- package/dist/storage/domains/filesystem/base.d.ts +0 -30
- package/dist/storage/domains/filesystem/base.d.ts.map +0 -1
- package/dist/storage/domains/filesystem/base.js +0 -78
- package/dist/storage/domains/filesystem/base.js.map +0 -1
package/dist/rules/dispatcher.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isUpdateEvent } from "../boards/board-events.js";
|
|
2
2
|
import "../boards/index.js";
|
|
3
|
-
import { INTAKE_ROUTE_METADATA_KEY,
|
|
3
|
+
import { INTAKE_ROUTE_METADATA_KEY, arrivalRuleFacts, landingPhase, placedByIntakeRoute, planEventMove, projectIntakeEvaluator, resolveIntake } from "../boards/intake-routing.js";
|
|
4
4
|
import "../boards/define-board.js";
|
|
5
|
-
import {
|
|
5
|
+
import { UNTRUSTED_PULL_REQUESTS_KEY, isOpenPullRequestSource, isPullRequestCard, pullRequestSources, pullRequestTrustKey, trustedPullRequestSource } from "../work-items/change-requests.js";
|
|
6
|
+
import { boardFlow, boardForWorkItem, cardBoardFlow, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
|
|
6
7
|
import { autoApprovedExitTool, startsInAutoPhase } from "../boards/phase-automation.js";
|
|
7
8
|
import { toBoardSource } from "../boards/project-boards.js";
|
|
8
9
|
import { moveCardToBoard } from "../boards/relocate.js";
|
|
9
|
-
import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
|
|
10
|
-
import { cardRuleFacts } from "../boards/card-facts.js";
|
|
10
|
+
import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, listThreadOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
|
|
11
11
|
import { resolvePromptInvocation, resolveSkillInvocation, resolveSkillResumeInvocation } from "../skills/service.js";
|
|
12
12
|
import { isHumanActorId } from "../storage/domains/audit/actors.js";
|
|
13
13
|
import { FACTORY_RULE_MATERIALIZATION_KEY, FactoryRunBindingSupersededError, WorkItemSourceConflictError, WorkItemUpdateConflictError, externalSourceKey } from "../storage/domains/work-items/base.js";
|
|
@@ -17,7 +17,9 @@ import { decisionOvertaken } from "./decision-applicability.js";
|
|
|
17
17
|
import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
18
18
|
import { isStatusEventDecision } from "./event-rules.js";
|
|
19
19
|
import { PHASE_GOAL_METADATA_KEY, endPhaseGoal, phaseGoalOf, startPhaseGoal } from "./phase-goal.js";
|
|
20
|
+
import { isRunBearingDecision } from "./run-bearing.js";
|
|
20
21
|
import { authorTrusted, externalSourceForWorkItem, workItemSource } from "./types.js";
|
|
22
|
+
import { eventRouteIngress, foldUpdate, updateGroup } from "./update-fold.js";
|
|
21
23
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
|
|
22
24
|
import { RequestContext } from "@mastra/core/request-context";
|
|
23
25
|
import { PROVIDER_CALL_ERROR_NAME, classifyProviderError } from "@mastra/core/error";
|
|
@@ -35,14 +37,17 @@ const MAX_BACKOFF_MS = 6e4;
|
|
|
35
37
|
const RUN_REGISTRY_HEARTBEAT_MS = 6e5;
|
|
36
38
|
const SKILL_COMPLETION_OBSERVATION_TIMEOUT_MS = 216e5;
|
|
37
39
|
const MAX_IN_FLIGHT = 10;
|
|
40
|
+
const isBookkeepingDecision = (decision) => !isRunBearingDecision(decision);
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* A wake a person is waiting on: a reply a person sent on the card's pull
|
|
43
|
+
* request or issue, which GitHub typed as a `User` (not an app or bot) with
|
|
44
|
+
* write access, that Factory did not write itself, and that came straight from
|
|
45
|
+
* the webhook rather than from a move or decision it caused. Everything else,
|
|
46
|
+
* including actors with no record of being a person, stays automated.
|
|
43
47
|
*/
|
|
44
|
-
const
|
|
45
|
-
const
|
|
48
|
+
const isInteractiveDecision = (decision, { actor, causalChain }) => (decision.type === "sendMessage" || decision.type === "signalActivity") && decision.idleBehavior !== "persist" && causalChain.length === 0 && actor?.type === "github" && actor.human === true && actor.trusted === true && actor.factoryAuthored === false;
|
|
49
|
+
const isAutomatedRunDecision = (decision, provenance) => isRunBearingDecision(decision) && !isInteractiveDecision(decision, provenance);
|
|
50
|
+
const MAX_INTERACTIVE_IN_FLIGHT = 2;
|
|
46
51
|
const BOOKKEEPING_MAX_IN_FLIGHT = 4;
|
|
47
52
|
const STALE_BINDING_SWEEP_INTERVAL_MS = 6e5;
|
|
48
53
|
const STALE_BINDING_TTL_MS = 864e5;
|
|
@@ -50,7 +55,18 @@ const RECONCILE_INTERVAL_MS = 3e4;
|
|
|
50
55
|
/** The card moved on before this run could act; it settles as superseded, not succeeded. */
|
|
51
56
|
var FactoryDecisionSuperseded = class extends Error {};
|
|
52
57
|
/** The decision cannot act yet and did nothing: it goes back to the queue and is claimed again later. */
|
|
53
|
-
var FactoryDecisionPostponed = class extends Error {
|
|
58
|
+
var FactoryDecisionPostponed = class extends Error {
|
|
59
|
+
availableAt;
|
|
60
|
+
constructor(availableAt) {
|
|
61
|
+
super();
|
|
62
|
+
this.availableAt = availableAt;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* How long an update waits for more updates to the same card before its routes run: a burst of
|
|
67
|
+
* label or assignee changes within this window becomes one event.
|
|
68
|
+
*/
|
|
69
|
+
const UPDATE_BURST_MS = 5e3;
|
|
54
70
|
const POSTPONE_MS = 1e4;
|
|
55
71
|
/** A run that ran and ended in error; the session's own listener reports it to followers. */
|
|
56
72
|
var RunEndedInError = class extends FactoryDispatchError {};
|
|
@@ -328,12 +344,31 @@ async function awaitNotification(send, requireDelivery = false) {
|
|
|
328
344
|
throw new FactoryDispatchError("notification_delivery_failed", `Factory notification delivery failed: ${sanitizeDispatchError(error)}`, { cause: error });
|
|
329
345
|
}
|
|
330
346
|
}
|
|
347
|
+
/** Card metadata key: the facts each linked pull request joined the card with, by its trust key. */
|
|
348
|
+
const LINKED_PULL_REQUESTS_KEY = "linkedPullRequests";
|
|
349
|
+
function linkedPullRequests(metadata) {
|
|
350
|
+
const links = metadata?.[LINKED_PULL_REQUESTS_KEY];
|
|
351
|
+
return links && typeof links === "object" && !Array.isArray(links) ? links : {};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A pull request's link to `card`, read off the card it joins. Only another trusted, open pull
|
|
355
|
+
* request counts as one the card already has: an outsider's can't keep a maintainer's from Review.
|
|
356
|
+
*/
|
|
357
|
+
function linkFacts(card, trusted, trustKey) {
|
|
358
|
+
return {
|
|
359
|
+
trusted,
|
|
360
|
+
phase: card.stages.length === 1 ? card.stages[0] : null,
|
|
361
|
+
hasPullRequest: pullRequestSources(card).some((source) => pullRequestTrustKey(source) !== trustKey && isOpenPullRequestSource(source) && trustedPullRequestSource(card, source))
|
|
362
|
+
};
|
|
363
|
+
}
|
|
331
364
|
var FactoryDecisionDispatcher = class {
|
|
332
365
|
#audit;
|
|
333
366
|
#controller;
|
|
334
367
|
#transitionService;
|
|
335
368
|
#boards;
|
|
336
369
|
#intakeRoutes;
|
|
370
|
+
/** Forced on every project; undefined: each project's own setting. */
|
|
371
|
+
#intakeEvaluator;
|
|
337
372
|
#storage;
|
|
338
373
|
#ownerId;
|
|
339
374
|
#autoApproving = /* @__PURE__ */ new Set();
|
|
@@ -359,6 +394,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
359
394
|
#resolveLinkedWorkItemParentId;
|
|
360
395
|
#factoryProjectExists;
|
|
361
396
|
#maxInFlight;
|
|
397
|
+
#maxInteractiveInFlight;
|
|
362
398
|
#staleBindingSweepIntervalMs;
|
|
363
399
|
#staleBindingTtlMs;
|
|
364
400
|
#lastStaleBindingSweepAt;
|
|
@@ -378,6 +414,8 @@ var FactoryDecisionDispatcher = class {
|
|
|
378
414
|
#timer;
|
|
379
415
|
/** Starts and run-bearing decisions; capped by `maxInFlight`. */
|
|
380
416
|
#runInFlight = /* @__PURE__ */ new Set();
|
|
417
|
+
/** Wakes a person is waiting on; capped by `maxInteractiveInFlight`, borrowing free run slots past it. */
|
|
418
|
+
#interactiveInFlight = /* @__PURE__ */ new Set();
|
|
381
419
|
/** Fast board bookkeeping (transitions, linked-card upserts); its own small cap. */
|
|
382
420
|
#bookkeepingInFlight = /* @__PURE__ */ new Set();
|
|
383
421
|
/** Background work awaited on stop but outside both caps. */
|
|
@@ -389,6 +427,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
389
427
|
this.#transitionService = options.transitionService;
|
|
390
428
|
this.#boards = toBoardSource(options.boards);
|
|
391
429
|
this.#intakeRoutes = options.intakeRoutes;
|
|
430
|
+
this.#intakeEvaluator = options.intakeEvaluator;
|
|
392
431
|
this.#storage = options.storage;
|
|
393
432
|
this.#ownerId = options.ownerId ?? `factory-dispatcher:${globalThis.crypto.randomUUID()}`;
|
|
394
433
|
this.#reconcileToolResults = options.reconcileToolResults;
|
|
@@ -402,6 +441,8 @@ var FactoryDecisionDispatcher = class {
|
|
|
402
441
|
this.#factoryProjectExists = options.factoryProjectExists;
|
|
403
442
|
const maxInFlight = options.maxInFlight ?? MAX_IN_FLIGHT;
|
|
404
443
|
this.#maxInFlight = Number.isFinite(maxInFlight) && maxInFlight > 0 ? Math.floor(maxInFlight) : MAX_IN_FLIGHT;
|
|
444
|
+
const maxInteractiveInFlight = options.maxInteractiveInFlight ?? MAX_INTERACTIVE_IN_FLIGHT;
|
|
445
|
+
this.#maxInteractiveInFlight = Number.isFinite(maxInteractiveInFlight) && maxInteractiveInFlight >= 0 ? Math.floor(maxInteractiveInFlight) : MAX_INTERACTIVE_IN_FLIGHT;
|
|
405
446
|
this.#staleBindingSweepIntervalMs = positiveMs(options.staleBindingSweepIntervalMs, STALE_BINDING_SWEEP_INTERVAL_MS);
|
|
406
447
|
this.#staleBindingTtlMs = positiveMs(options.staleBindingTtlMs, STALE_BINDING_TTL_MS);
|
|
407
448
|
this.#reconcileIntervalMs = positiveMs(options.reconcileIntervalMs, RECONCILE_INTERVAL_MS);
|
|
@@ -422,6 +463,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
422
463
|
await this.#loop;
|
|
423
464
|
await Promise.allSettled([
|
|
424
465
|
...this.#runInFlight,
|
|
466
|
+
...this.#interactiveInFlight,
|
|
425
467
|
...this.#bookkeepingInFlight,
|
|
426
468
|
...this.#backgroundInFlight
|
|
427
469
|
]);
|
|
@@ -454,11 +496,19 @@ var FactoryDecisionDispatcher = class {
|
|
|
454
496
|
this.#reconcileOwed = true;
|
|
455
497
|
this.wake();
|
|
456
498
|
}
|
|
457
|
-
/**
|
|
499
|
+
/**
|
|
500
|
+
* Run slots this process holds now, out of its caps. Per process: other
|
|
501
|
+
* replicas keep their own. `inUse` counts automated slots, including any a
|
|
502
|
+
* person's wake borrowed once the interactive reserve was full.
|
|
503
|
+
*/
|
|
458
504
|
runSlots() {
|
|
459
505
|
return {
|
|
460
506
|
inUse: this.#runInFlight.size,
|
|
461
|
-
cap: this.#maxInFlight
|
|
507
|
+
cap: this.#maxInFlight,
|
|
508
|
+
interactive: {
|
|
509
|
+
inUse: this.#interactiveInFlight.size,
|
|
510
|
+
cap: this.#maxInteractiveInFlight
|
|
511
|
+
}
|
|
462
512
|
};
|
|
463
513
|
}
|
|
464
514
|
async runOnce(now = /* @__PURE__ */ new Date()) {
|
|
@@ -494,7 +544,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
494
544
|
async #cycle() {
|
|
495
545
|
const now = /* @__PURE__ */ new Date();
|
|
496
546
|
this.#maybeSweepStaleBindings(now);
|
|
497
|
-
const active = this.#runInFlight.size > 0 || this.#bookkeepingInFlight.size > 0 || this.#controller.listActiveThreadRuns().length > 0 || this.#lastBoundThreadRunAt !== void 0 && now.getTime() - this.#lastBoundThreadRunAt < this.#reconcileIntervalMs;
|
|
547
|
+
const active = this.#runInFlight.size > 0 || this.#interactiveInFlight.size > 0 || this.#bookkeepingInFlight.size > 0 || this.#controller.listActiveThreadRuns().length > 0 || this.#lastBoundThreadRunAt !== void 0 && now.getTime() - this.#lastBoundThreadRunAt < this.#reconcileIntervalMs;
|
|
498
548
|
if (!this.#reconcileToolResults) this.#reconcileOwed = false;
|
|
499
549
|
else if (active) this.#reconcileOwed = true;
|
|
500
550
|
if (this.#reconcileOwed && this.#maybeReconcileToolResults(now) && !active) this.#reconcileOwed = false;
|
|
@@ -509,7 +559,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
509
559
|
console.error("Factory decision dispatch cycle failed", sanitizeDispatchError(error));
|
|
510
560
|
return POLL_MS;
|
|
511
561
|
}
|
|
512
|
-
if (full || this.#runInFlight.size > 0 || this.#bookkeepingInFlight.size > 0) return POLL_MS;
|
|
562
|
+
if (full || this.#runInFlight.size > 0 || this.#interactiveInFlight.size > 0 || this.#bookkeepingInFlight.size > 0) return POLL_MS;
|
|
513
563
|
const dueTimes = [];
|
|
514
564
|
if (this.#reconcileOwed) dueTimes.push((this.#lastReconcileAt?.getTime() ?? 0) + this.#reconcileIntervalMs);
|
|
515
565
|
try {
|
|
@@ -532,26 +582,44 @@ var FactoryDecisionDispatcher = class {
|
|
|
532
582
|
let full = false;
|
|
533
583
|
const leaseExpiresAt = new Date(now.getTime() + LEASE_MS);
|
|
534
584
|
const dispatches = [];
|
|
535
|
-
const
|
|
536
|
-
if (
|
|
537
|
-
const limit = Math.min(BATCH_SIZE,
|
|
585
|
+
const startCapacity = this.#maxInFlight - this.#runInFlight.size;
|
|
586
|
+
if (startCapacity > 0) {
|
|
587
|
+
const limit = Math.min(BATCH_SIZE, startCapacity);
|
|
538
588
|
const starts = await this.#storage.claimPendingStarts({
|
|
539
589
|
ownerId: this.#ownerId,
|
|
540
590
|
now,
|
|
541
591
|
leaseExpiresAt,
|
|
542
592
|
limit
|
|
543
593
|
});
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
594
|
+
full ||= starts.length >= limit;
|
|
595
|
+
dispatches.push(...starts.map((start) => this.#track(this.#runInFlight, this.#dispatchPendingStart(start, now))));
|
|
596
|
+
}
|
|
597
|
+
const reserveCapacity = Math.max(0, this.#maxInteractiveInFlight - this.#interactiveInFlight.size);
|
|
598
|
+
const interactiveCapacity = reserveCapacity + Math.max(0, this.#maxInFlight - this.#runInFlight.size);
|
|
599
|
+
if (interactiveCapacity > 0) {
|
|
600
|
+
const limit = Math.min(BATCH_SIZE, interactiveCapacity);
|
|
601
|
+
const decisions = await this.#storage.claimDeferredDecisions({
|
|
547
602
|
ownerId: this.#ownerId,
|
|
548
603
|
now,
|
|
549
604
|
leaseExpiresAt,
|
|
550
|
-
limit
|
|
551
|
-
decisionFilter:
|
|
552
|
-
})
|
|
553
|
-
full ||=
|
|
554
|
-
dispatches.push(...
|
|
605
|
+
limit,
|
|
606
|
+
decisionFilter: isInteractiveDecision
|
|
607
|
+
});
|
|
608
|
+
full ||= decisions.length >= limit;
|
|
609
|
+
dispatches.push(...decisions.map((decision, index) => this.#track(index < reserveCapacity ? this.#interactiveInFlight : this.#runInFlight, this.#dispatchDecision(decision, now))));
|
|
610
|
+
}
|
|
611
|
+
const runCapacity = this.#maxInFlight - this.#runInFlight.size;
|
|
612
|
+
if (runCapacity > 0) {
|
|
613
|
+
const limit = Math.min(BATCH_SIZE, runCapacity);
|
|
614
|
+
const decisions = await this.#storage.claimDeferredDecisions({
|
|
615
|
+
ownerId: this.#ownerId,
|
|
616
|
+
now,
|
|
617
|
+
leaseExpiresAt,
|
|
618
|
+
limit,
|
|
619
|
+
decisionFilter: isAutomatedRunDecision
|
|
620
|
+
});
|
|
621
|
+
full ||= decisions.length >= limit;
|
|
622
|
+
dispatches.push(...decisions.map((decision) => this.#track(this.#runInFlight, this.#dispatchDecision(decision, now))));
|
|
555
623
|
}
|
|
556
624
|
const bookkeepingCapacity = BOOKKEEPING_MAX_IN_FLIGHT - this.#bookkeepingInFlight.size;
|
|
557
625
|
if (bookkeepingCapacity > 0) {
|
|
@@ -635,7 +703,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
635
703
|
}
|
|
636
704
|
await this.#supersedeProposals(record, decision);
|
|
637
705
|
if (record.attempts <= 1) await this.#reviewQueuedOnce(record, decision);
|
|
638
|
-
await this.#withLease(async (leaseExpiresAt) => this.#storage.renewDeferredDecisionLease(leaseIdentity(record, this.#ownerId), leaseExpiresAt), async () => this.#executeDecision(record, decision));
|
|
706
|
+
await this.#withLease(async (leaseExpiresAt) => this.#storage.renewDeferredDecisionLease(leaseIdentity(record, this.#ownerId), leaseExpiresAt), async () => this.#executeDecision(record, decision, now));
|
|
639
707
|
executionCompleted = true;
|
|
640
708
|
if (!await this.#storage.completeDeferredDecision(leaseIdentity(record, this.#ownerId), /* @__PURE__ */ new Date())) throw new Error("Factory decision lease was lost before completion.");
|
|
641
709
|
if (this.#reviewWatched.has(record) || this.#reviewReplayed.has(record)) await this.#reviewStatus(record, decision, {
|
|
@@ -653,7 +721,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
653
721
|
return;
|
|
654
722
|
}
|
|
655
723
|
if (error instanceof FactoryDecisionPostponed) {
|
|
656
|
-
await this.#storage.postponeDeferredDecision(leaseIdentity(record, this.#ownerId), new Date(now.getTime() + POSTPONE_MS), /* @__PURE__ */ new Date());
|
|
724
|
+
await this.#storage.postponeDeferredDecision(leaseIdentity(record, this.#ownerId), error.availableAt ?? new Date(now.getTime() + POSTPONE_MS), /* @__PURE__ */ new Date());
|
|
657
725
|
return;
|
|
658
726
|
}
|
|
659
727
|
const failureCode = factoryDispatchFailureCode(error);
|
|
@@ -914,7 +982,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
914
982
|
if (reviewsFactoryAuthoredCode(boards, item, decision)) return false;
|
|
915
983
|
return !startsInAutoPhase(boards, item, decision);
|
|
916
984
|
}
|
|
917
|
-
async #executeDecision(record, decision) {
|
|
985
|
+
async #executeDecision(record, decision, now) {
|
|
918
986
|
const nextChain = [...record.causalChain, {
|
|
919
987
|
ingressId: record.idempotencyKey,
|
|
920
988
|
decisionType: decision.type
|
|
@@ -926,6 +994,11 @@ var FactoryDecisionDispatcher = class {
|
|
|
926
994
|
else await this.#applyTransition(record, decision, nextChain);
|
|
927
995
|
return;
|
|
928
996
|
case "routeEvent":
|
|
997
|
+
if (isUpdateEvent(decision.event.type)) {
|
|
998
|
+
const combined = await this.#foldUpdates(record, decision, now);
|
|
999
|
+
if (combined) await this.#routeEvent(record, combined, nextChain);
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
929
1002
|
await this.#routeEvent(record, decision.event, nextChain);
|
|
930
1003
|
return;
|
|
931
1004
|
case "upsertLinkedWorkItem":
|
|
@@ -1228,6 +1301,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1228
1301
|
if (existing && externalSourceKey(existing.externalSource) !== externalSourceKey(externalSourceForDecision(requested))) {
|
|
1229
1302
|
const source = externalSourceForDecision(requested);
|
|
1230
1303
|
const facts = workItemProviderAdapter(source).toSource(source, requested.metadata ?? null);
|
|
1304
|
+
if (requested.closesIssue?.workItemId === existing.id && record.workItemId === null) await this.#queueLinkedPullRequestOpened(record, requested, existing, causalChain);
|
|
1231
1305
|
if (facts?.state === "open") await this.#storage.syncWorkItemSource({
|
|
1232
1306
|
orgId: record.orgId,
|
|
1233
1307
|
factoryProjectId: record.factoryProjectId,
|
|
@@ -1247,16 +1321,20 @@ var FactoryDecisionDispatcher = class {
|
|
|
1247
1321
|
const attachBoards = await this.#boards.load(record);
|
|
1248
1322
|
if (await this.#attachLinkedItem(record, requested, requested.attachTo.workItemId, causalChain, (card) => cardBoardFlow(attachBoards, card).pullRequestReview !== void 0 ? { phase: null } : void 0)) return;
|
|
1249
1323
|
}
|
|
1250
|
-
if (!existing && requested.closesIssue && await this.#
|
|
1324
|
+
if (!existing && requested.closesIssue && await this.#linkClosedIssue(record, requested, causalChain)) return;
|
|
1251
1325
|
const materializedHere = existing?.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
|
|
1252
1326
|
if (materializedHere && requested.skipRules === true) return;
|
|
1253
1327
|
const boards = await this.#boards.load(record);
|
|
1254
1328
|
const renamed = existing ? null : await this.#linearCardByIssueId(record, requested, boards);
|
|
1255
1329
|
const current = existing ?? renamed;
|
|
1256
1330
|
const decision = !current ? await this.#routeArrival(record, requested, boards) : materializedHere ? await this.#resumeRoutedCard(record, current, requested, boards) : this.#keepRoutedCard(current, requested, boards);
|
|
1331
|
+
if (!decision) return;
|
|
1257
1332
|
if (materializedHere) for (const suffix of ["destination", "initial-entry"]) {
|
|
1258
1333
|
const replay = await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, `decision:${record.idempotencyKey}:${existing.id}:${suffix}`);
|
|
1259
|
-
if (replay?.status === "accepted" && replay.stage === decision.stage)
|
|
1334
|
+
if (replay?.status === "accepted" && replay.stage === decision.stage) {
|
|
1335
|
+
await this.#resolveNotRouted(record, decision.sourceKey);
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1260
1338
|
}
|
|
1261
1339
|
assertFactoryDecisionTarget(decision, boards);
|
|
1262
1340
|
const definition = boards.get(decision.board);
|
|
@@ -1295,6 +1373,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1295
1373
|
},
|
|
1296
1374
|
reuseMode: "preserve"
|
|
1297
1375
|
});
|
|
1376
|
+
const filed = () => this.#resolveNotRouted(record, decision.sourceKey);
|
|
1298
1377
|
const itemBoard = boardForWorkItem(result.item);
|
|
1299
1378
|
const itemFlow = itemBoard === decision.board ? void 0 : boardFlow(boards.get(itemBoard));
|
|
1300
1379
|
const keptReview = isPullRequestCard({ source: workItemSource(result.item.externalSource) }) ? itemFlow?.pullRequestReview : void 0;
|
|
@@ -1347,10 +1426,14 @@ var FactoryDecisionDispatcher = class {
|
|
|
1347
1426
|
});
|
|
1348
1427
|
item = fresh && fresh.revision !== item.revision ? fresh : null;
|
|
1349
1428
|
}
|
|
1429
|
+
await filed();
|
|
1350
1430
|
return;
|
|
1351
1431
|
}
|
|
1352
1432
|
const materializedByDecision = result.item.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
|
|
1353
|
-
if (!materializedByDecision && (decision.stage === initialPhase || !result.item.stages.includes(initialPhase)))
|
|
1433
|
+
if (!materializedByDecision && (decision.stage === initialPhase || !result.item.stages.includes(initialPhase))) {
|
|
1434
|
+
await filed();
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1354
1437
|
let expectedRevision = result.item.revision;
|
|
1355
1438
|
if (materializedByDecision) {
|
|
1356
1439
|
const initial = await this.#transitionService.transition({
|
|
@@ -1379,6 +1462,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1379
1462
|
}
|
|
1380
1463
|
expectedRevision = initial.revision;
|
|
1381
1464
|
}
|
|
1465
|
+
await filed();
|
|
1382
1466
|
if (decision.stage === initialPhase) return;
|
|
1383
1467
|
const moved = await this.#transitionService.transition({
|
|
1384
1468
|
orgId: record.orgId,
|
|
@@ -1407,7 +1491,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1407
1491
|
* own card, refused by `admit`, or another card took the record first), so the caller files the
|
|
1408
1492
|
* record as usual. `admit` runs again on a fresh read whenever the card changed in between.
|
|
1409
1493
|
*/
|
|
1410
|
-
async #attachLinkedItem(record, decision, workItemId, causalChain, admit) {
|
|
1494
|
+
async #attachLinkedItem(record, decision, workItemId, causalChain, admit, cardMetadata, afterAttach) {
|
|
1411
1495
|
if (this.#storage.legacyMode) return false;
|
|
1412
1496
|
const boards = await this.#boards.load(record);
|
|
1413
1497
|
let attached;
|
|
@@ -1425,7 +1509,8 @@ var FactoryDecisionDispatcher = class {
|
|
|
1425
1509
|
id: card.id,
|
|
1426
1510
|
source: externalSourceForDecision(decision),
|
|
1427
1511
|
metadata: decision.metadata ?? null,
|
|
1428
|
-
expectedRevision: card.revision
|
|
1512
|
+
expectedRevision: card.revision,
|
|
1513
|
+
...cardMetadata ? { cardMetadata: (metadata) => cardMetadata(metadata, card) } : {}
|
|
1429
1514
|
});
|
|
1430
1515
|
if (!result) return false;
|
|
1431
1516
|
attached = {
|
|
@@ -1440,6 +1525,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1440
1525
|
}
|
|
1441
1526
|
if (!attached) return false;
|
|
1442
1527
|
const { card, phase } = attached;
|
|
1528
|
+
await afterAttach?.(card);
|
|
1443
1529
|
const stage = card.stages.length === 1 ? card.stages[0] : void 0;
|
|
1444
1530
|
const board = boards.get(boardForWorkItem(card));
|
|
1445
1531
|
if (!phase || !stage || stage === phase) return true;
|
|
@@ -1469,74 +1555,172 @@ var FactoryDecisionDispatcher = class {
|
|
|
1469
1555
|
return true;
|
|
1470
1556
|
}
|
|
1471
1557
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1558
|
+
* Links a pull or merge request to the card of the issue it closes, whoever opened it: Factory
|
|
1559
|
+
* does this itself, before intake, wherever the card sits, so long as it is unfinished. Linking
|
|
1560
|
+
* runs nothing. An outsider's pull request is recorded as untrusted on the card, so it never
|
|
1561
|
+
* becomes the card's working pull request on its own; a person picks it. The card then gets the
|
|
1562
|
+
* pull request's `pull_request.opened`, so its board's own card-move rules decide whether it moves.
|
|
1476
1563
|
*/
|
|
1477
|
-
async #
|
|
1478
|
-
if (
|
|
1479
|
-
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1564
|
+
async #linkClosedIssue(record, decision, causalChain) {
|
|
1565
|
+
if (decision.skipRules === true || record.workItemId !== null) return false;
|
|
1566
|
+
const trusted = authorTrusted(decision.metadata);
|
|
1567
|
+
const trustKey = this.#pullRequestTrustKey(decision);
|
|
1568
|
+
return this.#attachLinkedItem(record, decision, decision.closesIssue.workItemId, causalChain, () => ({ phase: null }), (metadata, card) => {
|
|
1569
|
+
const links = linkedPullRequests(metadata);
|
|
1570
|
+
const withLink = {
|
|
1571
|
+
...metadata,
|
|
1572
|
+
[LINKED_PULL_REQUESTS_KEY]: {
|
|
1573
|
+
...links,
|
|
1574
|
+
[trustKey]: links[trustKey] ?? linkFacts(card, trusted, trustKey)
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
if (trusted) return withLink;
|
|
1578
|
+
const listed = metadata[UNTRUSTED_PULL_REQUESTS_KEY];
|
|
1579
|
+
const untrusted = Array.isArray(listed) ? listed.filter((entry) => typeof entry === "string") : [];
|
|
1580
|
+
return untrusted.includes(trustKey) ? withLink : {
|
|
1581
|
+
...withLink,
|
|
1582
|
+
[UNTRUSTED_PULL_REQUESTS_KEY]: [...untrusted, trustKey]
|
|
1583
|
+
};
|
|
1584
|
+
}, (card) => this.#queueLinkedPullRequestOpened(record, decision, card, causalChain));
|
|
1585
|
+
}
|
|
1586
|
+
/** The key a card lists an untrusted attached pull request under (see `UNTRUSTED_PULL_REQUESTS_KEY`). */
|
|
1587
|
+
#pullRequestTrustKey(decision) {
|
|
1588
|
+
const source = externalSourceForDecision(decision);
|
|
1589
|
+
return pullRequestTrustKey(workItemProviderAdapter(source).toSource(source, decision.metadata ?? null));
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Hands the card a linked pull request's `pull_request.opened`, with the facts saved when it
|
|
1593
|
+
* joined (the card's phase then, and whether a trusted open pull request was already on it), so
|
|
1594
|
+
* a retry after the card changed still describes the link as it happened. Keyed by the card and
|
|
1595
|
+
* the pull request, so whichever delivery files the pull request, and however often, the card
|
|
1596
|
+
* gets the event once.
|
|
1597
|
+
*/
|
|
1598
|
+
async #queueLinkedPullRequestOpened(record, decision, card, causalChain) {
|
|
1599
|
+
const sourceKey = externalSourceKey(externalSourceForDecision(decision));
|
|
1600
|
+
const key = `linked-pull-request:${card.id}:${sourceKey}`;
|
|
1601
|
+
const trustKey = this.#pullRequestTrustKey(decision);
|
|
1602
|
+
const link = linkedPullRequests(card.metadata)[trustKey] ?? linkFacts(card, authorTrusted(decision.metadata), trustKey);
|
|
1603
|
+
if ((await this.#storage.commitRuleEvaluation({
|
|
1604
|
+
orgId: record.orgId,
|
|
1605
|
+
factoryProjectId: record.factoryProjectId,
|
|
1606
|
+
workItemId: card.id,
|
|
1607
|
+
ingress: { identity: `decision:${key}` },
|
|
1608
|
+
expectedRevision: card.revision,
|
|
1609
|
+
actor: {
|
|
1610
|
+
type: "system",
|
|
1611
|
+
id: "factory-rule-dispatcher"
|
|
1612
|
+
},
|
|
1613
|
+
outcome: { status: "accepted" },
|
|
1614
|
+
decisions: [{
|
|
1615
|
+
type: "routeEvent",
|
|
1616
|
+
idempotencyKey: key,
|
|
1617
|
+
event: {
|
|
1618
|
+
type: "pull_request.opened",
|
|
1619
|
+
pullRequestTrusted: link.trusted,
|
|
1620
|
+
closedIssue: {
|
|
1621
|
+
phase: link.phase,
|
|
1622
|
+
hasPullRequest: link.hasPullRequest
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}],
|
|
1626
|
+
causalChain,
|
|
1627
|
+
now: /* @__PURE__ */ new Date()
|
|
1628
|
+
})).status === "stale") throw new Error("Factory linked pull request event was not queued: the work item changed concurrently.");
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Leaves a warning in the decision log for each card-move rule that matched but whose target
|
|
1632
|
+
* couldn't take the card; a redelivery of the same event replaces it.
|
|
1633
|
+
*/
|
|
1634
|
+
async #logSkippedRoutes(record, item, event, skipped) {
|
|
1635
|
+
if (!this.#intakeRoutes || skipped.length === 0) return;
|
|
1636
|
+
const scope = {
|
|
1482
1637
|
orgId: record.orgId,
|
|
1483
1638
|
factoryProjectId: record.factoryProjectId
|
|
1639
|
+
};
|
|
1640
|
+
const evaluator = await projectIntakeEvaluator(this.#intakeEvaluator, this.#intakeRoutes, scope);
|
|
1641
|
+
for (const skip of skipped) await this.#intakeRoutes.recordIntakeDecision(scope, {
|
|
1642
|
+
idempotencyKey: `rule-skipped:${record.idempotencyKey}:${skip.routeId}`,
|
|
1643
|
+
outcome: "rule_skipped",
|
|
1644
|
+
evaluator,
|
|
1645
|
+
boardKey: skip.boardKey,
|
|
1646
|
+
routeId: skip.routeId,
|
|
1647
|
+
reason: `The card-move rule matched ${event.type} but was skipped: ${skip.reason}.`,
|
|
1648
|
+
sourceKey: item.externalSource?.externalId ?? null,
|
|
1649
|
+
title: item.title,
|
|
1650
|
+
url: item.externalSource?.url ?? null
|
|
1484
1651
|
});
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
const route = resolveIntakeRoute(routes, {
|
|
1493
|
-
...arrival,
|
|
1494
|
-
...closedIssueRuleFacts(card)
|
|
1495
|
-
}, boards, card);
|
|
1496
|
-
return route?.type === "join" ? { phase: route.phase } : void 0;
|
|
1497
|
-
});
|
|
1652
|
+
}
|
|
1653
|
+
/** Marks the item's Not routed record, if any, resolved: its card is filed. */
|
|
1654
|
+
async #resolveNotRouted(record, sourceKey) {
|
|
1655
|
+
await this.#intakeRoutes?.resolveNotRouted({
|
|
1656
|
+
orgId: record.orgId,
|
|
1657
|
+
factoryProjectId: record.factoryProjectId
|
|
1658
|
+
}, sourceKey, "factory-rule-dispatcher");
|
|
1498
1659
|
}
|
|
1499
1660
|
/**
|
|
1500
|
-
* Places an arrival where
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1661
|
+
* Places an arrival where intake says (see `resolveIntake`). The board and phase an
|
|
1662
|
+
* integration's rule named don't count; only a decision placing the card outright (`skipRules`)
|
|
1663
|
+
* keeps its own. Undefined when no board takes it: it is logged Not routed and no card is filed.
|
|
1664
|
+
* Every decision is logged, keyed by the arrival's decision so a redelivery replaces its row.
|
|
1503
1665
|
*/
|
|
1504
1666
|
async #routeArrival(record, decision, boards) {
|
|
1505
|
-
if (
|
|
1667
|
+
if (decision.skipRules === true) return decision;
|
|
1506
1668
|
if (record.workItemId !== null) return decision;
|
|
1507
|
-
|
|
1669
|
+
if (!this.#intakeRoutes) {
|
|
1670
|
+
if (this.#intakeEvaluator !== "route-list") throw new Error("Intake rules are unavailable right now.");
|
|
1671
|
+
return decision;
|
|
1672
|
+
}
|
|
1673
|
+
const scope = {
|
|
1508
1674
|
orgId: record.orgId,
|
|
1509
1675
|
factoryProjectId: record.factoryProjectId
|
|
1676
|
+
};
|
|
1677
|
+
const evaluator = decision.idempotencyKey.startsWith("intake-route-again:") ? "intake-order" : await projectIntakeEvaluator(this.#intakeEvaluator, this.#intakeRoutes, scope);
|
|
1678
|
+
const [routes, order] = await Promise.all([this.#intakeRoutes.listIntakeRoutes(scope), evaluator === "intake-order" ? this.#intakeRoutes.readIntakeOrder(scope, { boards: [...boards.keys()] }) : void 0]);
|
|
1679
|
+
const facts = await arrivalRuleFacts(decision, {
|
|
1680
|
+
factoryProjectId: record.factoryProjectId,
|
|
1681
|
+
registry: boards,
|
|
1682
|
+
card: (id) => this.#storage.get({
|
|
1683
|
+
orgId: record.orgId,
|
|
1684
|
+
id
|
|
1685
|
+
})
|
|
1510
1686
|
});
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1687
|
+
const resolution = resolveIntake({
|
|
1688
|
+
evaluator,
|
|
1689
|
+
routes,
|
|
1690
|
+
order: order?.boardKeys ?? [],
|
|
1691
|
+
facts,
|
|
1692
|
+
registry: boards
|
|
1693
|
+
});
|
|
1694
|
+
const logged = {
|
|
1695
|
+
idempotencyKey: record.idempotencyKey,
|
|
1696
|
+
evaluator,
|
|
1697
|
+
sourceKey: decision.sourceKey,
|
|
1698
|
+
title: decision.title,
|
|
1699
|
+
url: decision.url
|
|
1522
1700
|
};
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1701
|
+
if (resolution.outcome === "not_routed") {
|
|
1702
|
+
await this.#intakeRoutes.recordIntakeDecision(scope, {
|
|
1703
|
+
...logged,
|
|
1704
|
+
outcome: "not_routed",
|
|
1705
|
+
reason: resolution.reason,
|
|
1706
|
+
arrival: { ...decision }
|
|
1707
|
+
});
|
|
1708
|
+
return;
|
|
1531
1709
|
}
|
|
1710
|
+
await this.#intakeRoutes.recordIntakeDecision(scope, {
|
|
1711
|
+
...logged,
|
|
1712
|
+
outcome: "placed",
|
|
1713
|
+
boardKey: resolution.board,
|
|
1714
|
+
routeId: resolution.routeId
|
|
1715
|
+
});
|
|
1532
1716
|
return {
|
|
1533
1717
|
...decision,
|
|
1534
|
-
board:
|
|
1535
|
-
stage:
|
|
1536
|
-
metadata: {
|
|
1718
|
+
board: resolution.board,
|
|
1719
|
+
stage: resolution.phase,
|
|
1720
|
+
...resolution.routeId !== null && { metadata: {
|
|
1537
1721
|
...decision.metadata,
|
|
1538
|
-
[
|
|
1539
|
-
}
|
|
1722
|
+
["intakeRouteId"]: resolution.routeId
|
|
1723
|
+
} }
|
|
1540
1724
|
};
|
|
1541
1725
|
}
|
|
1542
1726
|
/**
|
|
@@ -1619,11 +1803,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1619
1803
|
orgId: record.orgId,
|
|
1620
1804
|
factoryProjectId: record.factoryProjectId,
|
|
1621
1805
|
workItemId: item.id,
|
|
1622
|
-
ingress: {
|
|
1623
|
-
identity: `decision:${messageKey}@${moved.revision}`,
|
|
1624
|
-
triggerType: "transition.message"
|
|
1625
|
-
},
|
|
1626
|
-
configVersion: this.#transitionService.configVersion,
|
|
1806
|
+
ingress: { identity: `decision:${messageKey}@${moved.revision}` },
|
|
1627
1807
|
expectedRevision: moved.revision,
|
|
1628
1808
|
actor: record.actor ?? {
|
|
1629
1809
|
type: "system",
|
|
@@ -1658,41 +1838,39 @@ var FactoryDecisionDispatcher = class {
|
|
|
1658
1838
|
* moves nothing twice.
|
|
1659
1839
|
*/
|
|
1660
1840
|
async #routeEvent(record, event, causalChain, fallback) {
|
|
1661
|
-
const identity =
|
|
1841
|
+
const identity = eventRouteIngress(record.idempotencyKey);
|
|
1662
1842
|
if (await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, identity)) return;
|
|
1663
1843
|
if (await this.#statusEventOvertaken(record)) throw new FactoryDecisionSuperseded();
|
|
1664
1844
|
const resolve = async () => {
|
|
1665
1845
|
const item = await this.#requireItem(record);
|
|
1666
|
-
const
|
|
1846
|
+
const boards = await this.#boards.load(record);
|
|
1847
|
+
const board = boards.get(boardForWorkItem(item));
|
|
1667
1848
|
if (!board) return void 0;
|
|
1668
|
-
const stage = item.stages.length === 1 ? item.stages[0] : void 0;
|
|
1669
|
-
const finished = stage !== void 0 && board.isTerminal(stage);
|
|
1670
|
-
if (!eventMovesCard(event.type, finished)) return void 0;
|
|
1671
1849
|
const routes = this.#intakeRoutes ? await this.#intakeRoutes.listIntakeRoutes({
|
|
1672
1850
|
orgId: record.orgId,
|
|
1673
1851
|
factoryProjectId: record.factoryProjectId
|
|
1674
1852
|
}) : [];
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
};
|
|
1680
|
-
const route = resolveEventRoute(routes, event, cardRuleFacts(item), board, hasPullRequest(item));
|
|
1681
|
-
if (!route) return fallback && isPullRequestEvent(event.type) ? {
|
|
1853
|
+
const skipped = [];
|
|
1854
|
+
const plan = planEventMove({
|
|
1855
|
+
routes,
|
|
1856
|
+
event,
|
|
1682
1857
|
item,
|
|
1683
|
-
|
|
1684
|
-
fallback:
|
|
1685
|
-
|
|
1686
|
-
|
|
1858
|
+
registry: boards,
|
|
1859
|
+
...fallback && { fallback: { stage: fallback.stage } },
|
|
1860
|
+
onSkip: (skip) => skipped.push(skip)
|
|
1861
|
+
});
|
|
1862
|
+
await this.#logSkippedRoutes(record, item, event, skipped);
|
|
1863
|
+
if (plan.outcome === "rule_default") return {
|
|
1687
1864
|
item,
|
|
1688
1865
|
board,
|
|
1689
1866
|
fallback: true
|
|
1690
1867
|
};
|
|
1691
|
-
if (
|
|
1868
|
+
if (plan.outcome !== "moves") return void 0;
|
|
1692
1869
|
return {
|
|
1693
1870
|
item,
|
|
1694
1871
|
board,
|
|
1695
|
-
route
|
|
1872
|
+
route: plan.move,
|
|
1873
|
+
target: boards.get(plan.move.board)
|
|
1696
1874
|
};
|
|
1697
1875
|
};
|
|
1698
1876
|
const first = await resolve();
|
|
@@ -1701,25 +1879,15 @@ var FactoryDecisionDispatcher = class {
|
|
|
1701
1879
|
if (fallback) await this.#applyTransition(record, fallback, causalChain);
|
|
1702
1880
|
return;
|
|
1703
1881
|
}
|
|
1704
|
-
if (!first.
|
|
1705
|
-
const binding = await this.#findBinding(record);
|
|
1706
|
-
const startedBy = binding ? first.item.sessions[binding.role]?.startedBy : void 0;
|
|
1707
|
-
if (startedBy) await this.#primeCredentials?.({
|
|
1708
|
-
orgId: record.orgId,
|
|
1709
|
-
userId: startedBy
|
|
1710
|
-
});
|
|
1711
|
-
const session = binding && startedBy ? await this.#findSession(binding, {
|
|
1712
|
-
userId: startedBy,
|
|
1713
|
-
orgId: record.orgId
|
|
1714
|
-
}) : void 0;
|
|
1715
|
-
if (binding && session && await this.#hasRunInFlight(session, binding)) throw new FactoryDecisionPostponed();
|
|
1716
|
-
}
|
|
1882
|
+
if (!first.target.isTerminal(first.route.phase) && await this.#cardRunInFlight(record, first.item)) throw new FactoryDecisionPostponed();
|
|
1717
1883
|
const { item, board, route } = first;
|
|
1884
|
+
const crossesBoards = route.board !== board.id;
|
|
1718
1885
|
const result = await this.#transitionService.transition({
|
|
1719
1886
|
orgId: record.orgId,
|
|
1720
1887
|
factoryProjectId: record.factoryProjectId,
|
|
1721
1888
|
workItemId: item.id,
|
|
1722
1889
|
board: board.id,
|
|
1890
|
+
...crossesBoards ? { toBoard: route.board } : {},
|
|
1723
1891
|
stage: route.phase,
|
|
1724
1892
|
expectedRevision: item.revision,
|
|
1725
1893
|
actor: {
|
|
@@ -1735,6 +1903,59 @@ var FactoryDecisionDispatcher = class {
|
|
|
1735
1903
|
eventRoute: { routeId: route.routeId }
|
|
1736
1904
|
});
|
|
1737
1905
|
if (result.status === "rejected" && result.code === "stale") throw new Error(`${result.code}: ${result.reason}`);
|
|
1906
|
+
if (result.status === "accepted" && crossesBoards) await this.#storage.supersedeDecisionsForWorkItem({
|
|
1907
|
+
orgId: record.orgId,
|
|
1908
|
+
factoryProjectId: record.factoryProjectId,
|
|
1909
|
+
workItemId: item.id,
|
|
1910
|
+
except: result.decisions.map((decision) => String(decision.idempotencyKey)),
|
|
1911
|
+
supersededAt: /* @__PURE__ */ new Date()
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1915
|
+
* Whether the card's session has a run in flight. A binding with no recorded owner never
|
|
1916
|
+
* started a run, so it has none.
|
|
1917
|
+
*/
|
|
1918
|
+
async #cardRunInFlight(record, item) {
|
|
1919
|
+
const binding = await this.#findBinding(record);
|
|
1920
|
+
const startedBy = binding ? item.sessions[binding.role]?.startedBy : void 0;
|
|
1921
|
+
if (!binding || !startedBy) return false;
|
|
1922
|
+
await this.#primeCredentials?.({
|
|
1923
|
+
orgId: record.orgId,
|
|
1924
|
+
userId: startedBy
|
|
1925
|
+
});
|
|
1926
|
+
const session = await this.#findSession(binding, {
|
|
1927
|
+
userId: startedBy,
|
|
1928
|
+
orgId: record.orgId
|
|
1929
|
+
});
|
|
1930
|
+
return session !== void 0 && await this.#hasRunInFlight(session, binding);
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* The one update event an update decision stands for, or undefined when it has nothing to do.
|
|
1934
|
+
* Updates to the same card of the same kind (work item or pull request, the card's own session
|
|
1935
|
+
* or anyone else) and to the same pull request fold into the newest one: an older one gives way to it, and the newest carries
|
|
1936
|
+
* the net change of every one since the group last moved the card, so a label added then removed
|
|
1937
|
+
* nets out. The newest waits until no update has arrived for {@link UPDATE_BURST_MS}, and one
|
|
1938
|
+
* from the card's own session also until the session's run ends.
|
|
1939
|
+
*/
|
|
1940
|
+
async #foldUpdates(record, decision, now) {
|
|
1941
|
+
if (!record.workItemId) return void 0;
|
|
1942
|
+
const group = updateGroup(await this.#storage.listDeferredDecisions(record.orgId, record.factoryProjectId, { workItemId: record.workItemId }), decision);
|
|
1943
|
+
const { superseded, since, event } = await foldUpdate(group, record.id, (other) => this.#moveCommitted(record, other));
|
|
1944
|
+
if (superseded) throw new FactoryDecisionSuperseded();
|
|
1945
|
+
const sameClaim = (other) => other.leaseOwner === record.leaseOwner && other.leaseExpiresAt?.getTime() === record.leaseExpiresAt?.getTime();
|
|
1946
|
+
if (since.some((other) => other.status === "leased" && !sameClaim(other))) throw new FactoryDecisionPostponed();
|
|
1947
|
+
const quietAt = record.createdAt.getTime() + UPDATE_BURST_MS;
|
|
1948
|
+
if (now.getTime() < quietAt) throw new FactoryDecisionPostponed(new Date(quietAt));
|
|
1949
|
+
if (decision.fromCardSession) {
|
|
1950
|
+
const item = await this.#requireItem(record);
|
|
1951
|
+
if (await this.#cardRunInFlight(record, item)) throw new FactoryDecisionPostponed();
|
|
1952
|
+
}
|
|
1953
|
+
return event;
|
|
1954
|
+
}
|
|
1955
|
+
/** Whether `other`'s card move committed, even if its decision never finished. */
|
|
1956
|
+
async #moveCommitted(record, other) {
|
|
1957
|
+
const identity = eventRouteIngress(other.idempotencyKey);
|
|
1958
|
+
return Boolean(await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, identity));
|
|
1738
1959
|
}
|
|
1739
1960
|
/**
|
|
1740
1961
|
* Whether a later status event was queued for the same card: the source's last word wins, so a
|
|
@@ -1920,13 +2141,27 @@ var FactoryDecisionDispatcher = class {
|
|
|
1920
2141
|
return this.#autoApproving.has(toolCallId);
|
|
1921
2142
|
}
|
|
1922
2143
|
/**
|
|
2144
|
+
* Whether a run is in flight on any of the card's active seats, as the board shows it: a run the
|
|
2145
|
+
* registry here holds on a seat's thread, whoever started it, or one live on another dispatcher.
|
|
2146
|
+
* A read-only probe: it never switches a session's thread.
|
|
2147
|
+
*/
|
|
2148
|
+
async hasRunInFlightOnCard({ orgId, factoryProjectId, workItemId }) {
|
|
2149
|
+
const bindings = (await this.#storage.listRunBindings(orgId, factoryProjectId, workItemId)).filter((binding) => binding.status === "active");
|
|
2150
|
+
const liveThreads = new Set(this.#controller.listActiveThreadRuns().map((active) => active.threadId));
|
|
2151
|
+
for (const binding of bindings) {
|
|
2152
|
+
if (liveThreads.has(binding.threadId)) return true;
|
|
2153
|
+
const session = await this.#controller.getSession(binding.sessionId);
|
|
2154
|
+
if (session && await this.#hasRunInFlight(session, binding)) return true;
|
|
2155
|
+
}
|
|
2156
|
+
return false;
|
|
2157
|
+
}
|
|
2158
|
+
/**
|
|
1923
2159
|
* Whether a run is in flight on `binding`: live here, or live on another dispatcher. An open-run
|
|
1924
|
-
* entry with nothing live behind it is an orphan of a dead process and does not count.
|
|
2160
|
+
* entry with nothing live behind it is an orphan of a dead process and does not count. Reads the
|
|
2161
|
+
* binding's own thread, which the session may have switched away from.
|
|
1925
2162
|
*/
|
|
1926
2163
|
async #hasRunInFlight(session, binding) {
|
|
1927
|
-
|
|
1928
|
-
if (open.length === 0) return false;
|
|
1929
|
-
if (open.some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) return true;
|
|
2164
|
+
if ((await listThreadOpenRuns(session, binding.threadId)).filter((entry) => entry.bindingId === binding.id).some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) return true;
|
|
1930
2165
|
return this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId);
|
|
1931
2166
|
}
|
|
1932
2167
|
/** Waits for the run in flight on `binding` to end, so a kickoff never overlaps it. */
|
|
@@ -2170,6 +2405,6 @@ const FACTORY_DISPATCH_CONSTANTS = {
|
|
|
2170
2405
|
maxInFlight: MAX_IN_FLIGHT,
|
|
2171
2406
|
reviewStatusTimeoutMs: REVIEW_STATUS_TIMEOUT_MS
|
|
2172
2407
|
};
|
|
2173
|
-
export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher,
|
|
2408
|
+
export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher, UPDATE_BURST_MS, isInteractiveDecision };
|
|
2174
2409
|
|
|
2175
2410
|
//# sourceMappingURL=dispatcher.js.map
|