@mastra/factory 0.28.0-alpha.1 → 0.28.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -123
- package/dist/boards/board-events.d.ts +23 -3
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +44 -7
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +16 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/card-facts.d.ts +1 -1
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +4 -0
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/default-board.d.ts +7 -0
- package/dist/boards/default-board.d.ts.map +1 -0
- package/dist/boards/default-board.js +10 -0
- package/dist/boards/default-board.js.map +1 -0
- package/dist/boards/define-board.d.ts +39 -17
- package/dist/boards/define-board.d.ts.map +1 -1
- package/dist/boards/define-board.js +64 -42
- package/dist/boards/define-board.js.map +1 -1
- package/dist/boards/index.d.ts +5 -8
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +5 -19
- package/dist/boards/intake-routing.d.ts +27 -5
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +69 -16
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/legacy-plan-role.d.ts.map +1 -1
- package/dist/boards/legacy-plan-role.js +7 -2
- package/dist/boards/legacy-plan-role.js.map +1 -1
- package/dist/boards/phase-automation.d.ts +7 -0
- package/dist/boards/phase-automation.d.ts.map +1 -1
- package/dist/boards/phase-automation.js +16 -5
- package/dist/boards/phase-automation.js.map +1 -1
- package/dist/boards/phase-runner.d.ts +18 -10
- package/dist/boards/phase-runner.d.ts.map +1 -1
- package/dist/boards/phase-runner.js +39 -34
- package/dist/boards/phase-runner.js.map +1 -1
- package/dist/boards/project-boards.d.ts +9 -6
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +56 -18
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/registry.d.ts.map +1 -1
- package/dist/boards/registry.js +3 -1
- package/dist/boards/registry.js.map +1 -1
- package/dist/boards/relocate.d.ts +1 -1
- package/dist/boards/relocate.d.ts.map +1 -1
- package/dist/boards/relocate.js +3 -2
- package/dist/boards/relocate.js.map +1 -1
- package/dist/boards/review.d.ts +5 -2
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +12 -11
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +159 -20
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +256 -23
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/stored-board.d.ts +32 -18
- package/dist/boards/stored-board.d.ts.map +1 -1
- package/dist/boards/stored-board.js +31 -97
- package/dist/boards/stored-board.js.map +1 -1
- package/dist/boards/work-migrations.d.ts +19 -0
- package/dist/boards/work-migrations.d.ts.map +1 -0
- package/dist/boards/work-migrations.js +257 -0
- package/dist/boards/work-migrations.js.map +1 -0
- package/dist/boards/work-routes.d.ts +53 -0
- package/dist/boards/work-routes.d.ts.map +1 -0
- package/dist/boards/work-routes.js +256 -0
- package/dist/boards/work-routes.js.map +1 -0
- package/dist/boards/work.d.ts +8 -19
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +38 -270
- package/dist/boards/work.js.map +1 -1
- package/dist/factory.d.ts +3 -3
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +58 -30
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/integrations/base.d.ts +6 -2
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/closing-references.d.ts +15 -0
- package/dist/integrations/closing-references.d.ts.map +1 -0
- package/dist/integrations/closing-references.js +69 -0
- package/dist/integrations/closing-references.js.map +1 -0
- package/dist/integrations/github/default-rules.d.ts +15 -66
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +129 -71
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +3 -1
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/pull-request-source.d.ts +8 -0
- package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
- package/dist/integrations/github/pull-request-source.js +17 -0
- package/dist/integrations/github/pull-request-source.js.map +1 -0
- package/dist/integrations/github/review-status-reporter.d.ts.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +7 -3
- package/dist/integrations/github/review-status-reporter.js.map +1 -1
- package/dist/integrations/github/routes.js +1 -1
- package/dist/integrations/github/rules.d.ts +13 -2
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +202 -34
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +2 -2
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/github/token-refresh.d.ts +2 -1
- package/dist/integrations/github/token-refresh.d.ts.map +1 -1
- package/dist/integrations/github/token-refresh.js.map +1 -1
- package/dist/integrations/gitlab/agent-tools.js +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +73 -31
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +106 -43
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.js +2 -1
- package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +11 -4
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +6 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +116 -23
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -1
- package/dist/integrations/incidentio/agent-tools.js +1 -1
- package/dist/integrations/incidentio/default-rules.js +3 -3
- package/dist/integrations/incidentio/default-rules.js.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.js +2 -1
- package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts +3 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +14 -11
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/agent-tools.js +1 -1
- package/dist/integrations/jira/default-rules.js +3 -3
- package/dist/integrations/jira/default-rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js +2 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts +3 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +14 -11
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/agent-tools.d.ts +9 -1
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
- package/dist/integrations/linear/agent-tools.js +80 -2
- package/dist/integrations/linear/agent-tools.js.map +1 -1
- package/dist/integrations/linear/default-rules.js +3 -3
- package/dist/integrations/linear/default-rules.js.map +1 -1
- package/dist/integrations/linear/integration.d.ts +4 -1
- package/dist/integrations/linear/integration.d.ts.map +1 -1
- package/dist/integrations/linear/integration.js +21 -1
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/linear/issue-reconciler.js +2 -1
- package/dist/integrations/linear/issue-reconciler.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +4 -3
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts +3 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +15 -12
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +33 -21
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/agent-tools.js +1 -1
- package/dist/integrations/platform/linear/integration.d.ts +1 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +6 -5
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/slack/chat-tools.js +1 -1
- package/dist/integrations/slack/reply-tool.js +1 -1
- package/dist/integrations/slack/share-file-tool.js +1 -1
- package/dist/integrations/slack/slack.d.ts +10 -4
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +19 -9
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +3 -2
- package/dist/links.js.map +1 -1
- package/dist/mcp/routes.js +2 -2
- package/dist/routes/attention-parked.d.ts +1 -0
- package/dist/routes/attention-parked.d.ts.map +1 -1
- package/dist/routes/attention-parked.js +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +4 -0
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +15 -0
- package/dist/routes/automation-runs.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 +1 -17
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +4 -0
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +15 -0
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +125 -14
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +34 -15
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts +4 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +8 -4
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +1 -0
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +8 -2
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +10 -5
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/running-packages.d.ts +13 -0
- package/dist/routes/running-packages.d.ts.map +1 -0
- package/dist/routes/running-packages.js +45 -0
- package/dist/routes/running-packages.js.map +1 -0
- package/dist/routes/surface.d.ts +10 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +104 -35
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +23 -3
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.d.ts.map +1 -1
- package/dist/rules/binding-context.js +1 -0
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +0 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +340 -42
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +33 -2
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +46 -11
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/index.d.ts +2 -4
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -3
- package/dist/rules/phase-goal.d.ts +54 -0
- package/dist/rules/phase-goal.d.ts.map +1 -0
- package/dist/rules/phase-goal.js +70 -0
- package/dist/rules/phase-goal.js.map +1 -0
- package/dist/rules/phase-tools.d.ts +11 -0
- package/dist/rules/phase-tools.d.ts.map +1 -0
- package/dist/rules/phase-tools.js +19 -0
- package/dist/rules/phase-tools.js.map +1 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +112 -11
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.d.ts +4 -1
- package/dist/rules/review-source-tool.d.ts.map +1 -1
- package/dist/rules/review-source-tool.js +24 -4
- package/dist/rules/review-source-tool.js.map +1 -1
- package/dist/rules/rule-group.d.ts +1 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +2 -1
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +5 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +9 -3
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +39 -28
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +2 -7
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +61 -54
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +83 -29
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +5 -41
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +32 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/secret-encryption.d.ts +21 -0
- package/dist/secret-encryption.d.ts.map +1 -1
- package/dist/secret-encryption.js +31 -4
- package/dist/secret-encryption.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +6 -2
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +8 -4
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-threads.d.ts +2 -3
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/source-control-tools.js +1 -1
- package/dist/session/work-item-state-processor.d.ts +27 -0
- package/dist/session/work-item-state-processor.d.ts.map +1 -0
- package/dist/session/work-item-state-processor.js +288 -0
- package/dist/session/work-item-state-processor.js.map +1 -0
- package/dist/storage/domains/boards/base.d.ts +44 -27
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +76 -121
- 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 +12 -0
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +32 -2
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +109 -26
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +24 -2
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +118 -8
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
- package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
- package/dist/storage/domains/work-items/legacy-review.js +95 -0
- package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +12 -4
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
- package/dist/storage/domains/work-items/metrics.js +14 -32
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +2 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +5 -0
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/tools/approval-tools.d.ts.map +1 -1
- package/dist/tools/approval-tools.js +28 -9
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts +3 -0
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +2 -1
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/read-tools.d.ts +8 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +83 -23
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/reports.d.ts +1 -0
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +2 -1
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/run-watch.d.ts +1 -1
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +1 -0
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/sandbox-tools.js +1 -1
- package/dist/tools/session-tools.js +1 -1
- package/dist/tools/sessions-state-processor.d.ts +2 -0
- package/dist/tools/sessions-state-processor.d.ts.map +1 -1
- package/dist/tools/sessions-state-processor.js +4 -2
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts +2 -0
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js +2 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.js +3 -3
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +13 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +16 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts +6 -0
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +25 -1
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +1 -0
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +53 -10
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +11 -9
- package/factory-skills/factory-build/SKILL.md +64 -0
- package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
- package/factory-skills/factory-gitlab-review/SKILL.md +2 -2
- package/factory-skills/factory-plan/SKILL.md +8 -10
- package/factory-skills/factory-rereview/SKILL.md +3 -3
- package/factory-skills/factory-review/SKILL.md +14 -4
- package/factory-skills/factory-self-review/SKILL.md +31 -11
- package/factory-skills/factory-triage/SKILL.md +25 -10
- package/package.json +9 -9
- package/dist/boards/index.js.map +0 -1
- package/dist/boards/pull-request-review.d.ts +0 -14
- package/dist/boards/pull-request-review.d.ts.map +0 -1
- package/dist/boards/pull-request-review.js +0 -81
- package/dist/boards/pull-request-review.js.map +0 -1
- package/dist/boards/work-tool-rules.d.ts +0 -8
- package/dist/boards/work-tool-rules.d.ts.map +0 -1
- package/dist/boards/work-tool-rules.js +0 -19
- package/dist/boards/work-tool-rules.js.map +0 -1
- package/dist/rules/resolve.d.ts +0 -15
- package/dist/rules/resolve.d.ts.map +0 -1
- package/dist/rules/resolve.js +0 -22
- package/dist/rules/resolve.js.map +0 -1
- package/factory-skills/factory-complete-issue/SKILL.md +0 -24
package/dist/rules/dispatcher.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { eventMovesCard, isPullRequestEvent } from "../boards/board-events.js";
|
|
1
2
|
import "../boards/index.js";
|
|
2
|
-
import { INTAKE_ROUTE_METADATA_KEY, landingPhase, placedByIntakeRoute, resolveEventRoute, resolveIntakePlacement, routesHandleEvent } from "../boards/intake-routing.js";
|
|
3
|
-
import
|
|
3
|
+
import { INTAKE_ROUTE_METADATA_KEY, closedIssueRuleFacts, landingPhase, placedByIntakeRoute, resolveEventRoute, resolveIntakePlacement, resolveIntakeRoute, routesHandleEvent } from "../boards/intake-routing.js";
|
|
4
|
+
import "../boards/define-board.js";
|
|
5
|
+
import { boardFlow, boardForWorkItem, cardBoardFlow, hasPullRequest, isPullRequestCard, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
|
|
4
6
|
import { autoApprovedExitTool, startsInAutoPhase } from "../boards/phase-automation.js";
|
|
5
7
|
import { toBoardSource } from "../boards/project-boards.js";
|
|
6
8
|
import { moveCardToBoard } from "../boards/relocate.js";
|
|
@@ -9,12 +11,13 @@ import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewh
|
|
|
9
11
|
import { resolvePromptInvocation, resolveSkillInvocation, resolveSkillResumeInvocation } from "../skills/service.js";
|
|
10
12
|
import { isHumanActorId } from "../storage/domains/audit/actors.js";
|
|
11
13
|
import { withWorkItemFeed } from "../storage/domains/comments/feed-context.js";
|
|
12
|
-
import { FACTORY_RULE_MATERIALIZATION_KEY } from "../storage/domains/work-items/base.js";
|
|
14
|
+
import { FACTORY_RULE_MATERIALIZATION_KEY, WorkItemSourceConflictError, WorkItemUpdateConflictError, externalSourceKey } from "../storage/domains/work-items/base.js";
|
|
13
15
|
import { workItemProviderAdapter } from "../work-items/providers/index.js";
|
|
14
16
|
import { decisionOvertaken } from "./decision-applicability.js";
|
|
15
17
|
import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
16
18
|
import { isStatusEventDecision } from "./event-rules.js";
|
|
17
|
-
import {
|
|
19
|
+
import { PHASE_GOAL_METADATA_KEY, endPhaseGoal, phaseGoalOf, startPhaseGoal } from "./phase-goal.js";
|
|
20
|
+
import { authorTrusted, externalSourceForWorkItem, workItemSource } from "./types.js";
|
|
18
21
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
|
|
19
22
|
import { RequestContext } from "@mastra/core/request-context";
|
|
20
23
|
import { PROVIDER_CALL_ERROR_NAME, classifyProviderError } from "@mastra/core/error";
|
|
@@ -78,11 +81,11 @@ function runErrorFailure(label, error) {
|
|
|
78
81
|
if (!cause) return new RunEndedInError("run_failed", `${label} ended in error.`);
|
|
79
82
|
return new RunEndedInError(runErrorCode(error, cause), `${label} ended in error: ${cause}`);
|
|
80
83
|
}
|
|
81
|
-
/** A
|
|
82
|
-
function
|
|
83
|
-
if (!decision || typeof decision !== "object") return
|
|
84
|
+
/** A run in the review seat: a pull request review, unless it is the card's board's self-review. */
|
|
85
|
+
function reviewSeatSkill(decision) {
|
|
86
|
+
if (!decision || typeof decision !== "object") return void 0;
|
|
84
87
|
const value = decision;
|
|
85
|
-
return value.type === "invokeSkill" && value.role === "review";
|
|
88
|
+
return value.type === "invokeSkill" && value.role === "review" ? value : void 0;
|
|
86
89
|
}
|
|
87
90
|
function isTerminalFailure(attempts, failureCode) {
|
|
88
91
|
return attempts >= MAX_ATTEMPTS || !factoryDispatchFailureMetadata(failureCode).canRetry;
|
|
@@ -267,12 +270,18 @@ function requestsConsent(boards, record, decision) {
|
|
|
267
270
|
if (decision.type !== "transition" || !externalActor(record.actor)) return false;
|
|
268
271
|
return (resolvePhaseSemantics(boards, decision.board, decision.stage)?.kind ?? "working") === "working";
|
|
269
272
|
}
|
|
270
|
-
function reviewsFactoryAuthoredCode(item, decision) {
|
|
273
|
+
function reviewsFactoryAuthoredCode(boards, item, decision) {
|
|
271
274
|
if (item.metadata?.factoryAuthored !== true) return false;
|
|
272
|
-
if (decision.type === "transition")
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
if (decision.type === "transition") {
|
|
276
|
+
const flow = boardFlow(boards.get(decision.board));
|
|
277
|
+
return decision.stage === flow.pullRequestReview && reviewsPullRequest({
|
|
278
|
+
flow,
|
|
279
|
+
item: {
|
|
280
|
+
source: workItemSource(item.externalSource),
|
|
281
|
+
workItem: item.workItem
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
276
285
|
return decision.type === "invokeSkill" && decision.role === "review";
|
|
277
286
|
}
|
|
278
287
|
function leaseIdentity(record, ownerId) {
|
|
@@ -652,7 +661,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
652
661
|
* registering there can still be live in this process, so wait it out too.
|
|
653
662
|
*/
|
|
654
663
|
async #replayLanded(record, decision, session, runStillActive) {
|
|
655
|
-
if (!isReviewRun(decision)) return;
|
|
664
|
+
if (!await this.#isReviewRun(record, decision)) return;
|
|
656
665
|
if (runStillActive()) {
|
|
657
666
|
const run = watchRun(session, {
|
|
658
667
|
timeoutMs: this.#skillCompletionObservationTimeoutMs,
|
|
@@ -668,6 +677,110 @@ var FactoryDecisionDispatcher = class {
|
|
|
668
677
|
}
|
|
669
678
|
this.#reviewReplayed.add(record);
|
|
670
679
|
}
|
|
680
|
+
/**
|
|
681
|
+
* Holds the goal a phase's run pursues on the session's thread, and names it on the card so
|
|
682
|
+
* leaving the phase ends it. Keyed on the decision: a retry finds the goal already held.
|
|
683
|
+
*/
|
|
684
|
+
async #setPhaseGoal(record, goal, session, binding) {
|
|
685
|
+
const item = record.workItemId ? await this.#storage.get({
|
|
686
|
+
orgId: record.orgId,
|
|
687
|
+
id: record.workItemId
|
|
688
|
+
}) : null;
|
|
689
|
+
const phaseKey = item?.stages.length === 1 ? item.stages[0] : void 0;
|
|
690
|
+
const objective = await startPhaseGoal(session.machinery.getAgent(), {
|
|
691
|
+
threadId: binding.threadId,
|
|
692
|
+
resourceId: binding.resourceId,
|
|
693
|
+
goalId: record.id,
|
|
694
|
+
objective: goal.objective,
|
|
695
|
+
maxRuns: goal.maxRuns,
|
|
696
|
+
judgeModelId: session.model.get() || void 0
|
|
697
|
+
});
|
|
698
|
+
if (!objective) throw new FactoryDispatchError("run_configuration_invalid", "The Factory session has no storage to hold a goal.");
|
|
699
|
+
if (!item || !phaseKey) return objective;
|
|
700
|
+
const stamp = {
|
|
701
|
+
phaseKey,
|
|
702
|
+
goalId: record.id,
|
|
703
|
+
threadId: binding.threadId,
|
|
704
|
+
sessionId: binding.sessionId
|
|
705
|
+
};
|
|
706
|
+
if (phaseGoalOf(item.metadata)?.goalId !== record.id) await this.#storage.update({
|
|
707
|
+
orgId: record.orgId,
|
|
708
|
+
id: item.id,
|
|
709
|
+
userId: "factory",
|
|
710
|
+
patch: { metadata: { [PHASE_GOAL_METADATA_KEY]: stamp } }
|
|
711
|
+
});
|
|
712
|
+
const after = await this.#storage.get({
|
|
713
|
+
orgId: record.orgId,
|
|
714
|
+
id: item.id
|
|
715
|
+
});
|
|
716
|
+
if (after?.stages.length !== 1 || after.stages[0] !== phaseKey) {
|
|
717
|
+
await endPhaseGoal(stamp, {
|
|
718
|
+
agentFor: async () => session.machinery.getAgent(),
|
|
719
|
+
store: async () => void 0
|
|
720
|
+
});
|
|
721
|
+
throw new FactoryDecisionSuperseded();
|
|
722
|
+
}
|
|
723
|
+
return objective;
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Shows the goal in the thread once its run has the kickoff. A goal whose reminder never landed
|
|
727
|
+
* is paused rather than left judging a run nobody was told about; the retry resumes it.
|
|
728
|
+
*/
|
|
729
|
+
async #remindPhaseGoal(record, goal, session, binding, requestContext) {
|
|
730
|
+
const reminderId = `${record.id}:goal`;
|
|
731
|
+
if ((await session.thread.listActiveMessages()).some((message) => message.id === reminderId)) return;
|
|
732
|
+
const agent = session.machinery.getAgent();
|
|
733
|
+
if (goal.status === "paused") await agent.updateObjectiveOptions({
|
|
734
|
+
threadId: binding.threadId,
|
|
735
|
+
status: "active"
|
|
736
|
+
});
|
|
737
|
+
try {
|
|
738
|
+
const settled = await session.sendSignal({
|
|
739
|
+
id: reminderId,
|
|
740
|
+
type: "system-reminder",
|
|
741
|
+
contents: goal.objective,
|
|
742
|
+
attributes: { type: "goal" },
|
|
743
|
+
metadata: {
|
|
744
|
+
goalId: goal.id,
|
|
745
|
+
goalMaxTurns: goal.maxRuns,
|
|
746
|
+
judgeModelId: goal.judgeModelId
|
|
747
|
+
}
|
|
748
|
+
}, {
|
|
749
|
+
requestContext,
|
|
750
|
+
requireDelivery: true
|
|
751
|
+
}).accepted;
|
|
752
|
+
if (settled.action !== "wake" && settled.action !== "deliver") throw new FactoryDispatchError("notification_delivery_failed", `Factory goal reminder did not reach the agent (${String(settled.action)}).`);
|
|
753
|
+
} catch (error) {
|
|
754
|
+
await agent.updateObjectiveOptions({
|
|
755
|
+
threadId: binding.threadId,
|
|
756
|
+
status: "paused"
|
|
757
|
+
});
|
|
758
|
+
throw error;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/** A retried decision whose kickoff already landed: make sure its goal is held and shown. */
|
|
762
|
+
async #startPhaseGoal(record, goal, session, binding, requestContext) {
|
|
763
|
+
const objective = await this.#setPhaseGoal(record, goal, session, binding);
|
|
764
|
+
await this.#remindPhaseGoal(record, objective, session, binding, requestContext);
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* A pull request review run: the only runs that keep a status comment on the pull request. A
|
|
768
|
+
* review-seat run of the skill the card's board self-reviews with checks the builder's own work
|
|
769
|
+
* and reviews no pull request, even on a card that carries one.
|
|
770
|
+
*/
|
|
771
|
+
async #isReviewRun(record, decision) {
|
|
772
|
+
const run = reviewSeatSkill(decision);
|
|
773
|
+
if (!run) return false;
|
|
774
|
+
const item = record.workItemId ? await this.#storage.get({
|
|
775
|
+
orgId: record.orgId,
|
|
776
|
+
id: record.workItemId
|
|
777
|
+
}) : null;
|
|
778
|
+
if (!item) return true;
|
|
779
|
+
const board = (await this.#boards.load(record)).get(boardForWorkItem(item));
|
|
780
|
+
const selfReview = boardFlow(board).selfReview;
|
|
781
|
+
const phase = selfReview === void 0 ? void 0 : board?.phases[selfReview];
|
|
782
|
+
return phase?.kind !== "working" || phase.runner.skill !== run.skillName;
|
|
783
|
+
}
|
|
671
784
|
async #reviewQueuedOnce(record, decision) {
|
|
672
785
|
if (this.#reviewQueued.has(record)) return;
|
|
673
786
|
this.#reviewQueued.add(record);
|
|
@@ -676,7 +789,13 @@ var FactoryDecisionDispatcher = class {
|
|
|
676
789
|
/** Best-effort: a status comment is never worth failing or delaying the review it describes. */
|
|
677
790
|
async #reviewStatus(record, decision, step) {
|
|
678
791
|
const report = this.#reportReviewStatus;
|
|
679
|
-
if (!report || !record.workItemId
|
|
792
|
+
if (!report || !record.workItemId) return;
|
|
793
|
+
try {
|
|
794
|
+
if (!await this.#isReviewRun(record, decision)) return;
|
|
795
|
+
} catch (error) {
|
|
796
|
+
console.warn("Factory review status update failed", sanitizeDispatchError(error));
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
680
799
|
const event = {
|
|
681
800
|
orgId: record.orgId,
|
|
682
801
|
factoryProjectId: record.factoryProjectId,
|
|
@@ -771,7 +890,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
771
890
|
id: record.workItemId
|
|
772
891
|
}) : null;
|
|
773
892
|
if (item?.autonomyArmedAt != null) return false;
|
|
774
|
-
if (item && reviewsFactoryAuthoredCode(item, decision)) return false;
|
|
893
|
+
if (item && reviewsFactoryAuthoredCode(boards, item, decision)) return false;
|
|
775
894
|
if (item && startsInAutoPhase(boards, item, decision)) return false;
|
|
776
895
|
return !await this.#isAutoRunEnabled({
|
|
777
896
|
orgId: record.orgId,
|
|
@@ -836,7 +955,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
836
955
|
await this.#waitForOpenRun(session, binding, "Factory skill run");
|
|
837
956
|
if (await this.#roleSuperseded(record, decision.role)) throw new FactoryDecisionSuperseded();
|
|
838
957
|
if ((await this.#requireBinding(record, decision.role)).id !== binding.id) throw new FactoryDispatchError("session_unavailable", `Factory binding ${binding.id} changed while waiting for its open run to end.`);
|
|
839
|
-
if (await kickoffLanded())
|
|
958
|
+
if (await kickoffLanded()) {
|
|
959
|
+
if (decision.goal) await this.#startPhaseGoal(record, decision.goal, session, binding, requestContext);
|
|
960
|
+
return this.#replayLanded(record, decision, session, runStillActive);
|
|
961
|
+
}
|
|
840
962
|
if (await kickoffStale()) throw new FactoryDecisionSuperseded();
|
|
841
963
|
const kickoffContents = await withWorkItemFeed(this.#feedReader, {
|
|
842
964
|
orgId: record.orgId,
|
|
@@ -851,7 +973,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
851
973
|
type: "user",
|
|
852
974
|
tagName: "user"
|
|
853
975
|
};
|
|
854
|
-
if (await kickoffLanded())
|
|
976
|
+
if (await kickoffLanded()) {
|
|
977
|
+
if (decision.goal) await this.#startPhaseGoal(record, decision.goal, session, binding, requestContext);
|
|
978
|
+
return this.#replayLanded(record, decision, session, runStillActive);
|
|
979
|
+
}
|
|
855
980
|
if (await kickoffStale()) throw new FactoryDecisionSuperseded();
|
|
856
981
|
await this.#reviewQueuedOnce(record, decision);
|
|
857
982
|
if (decision.cancelInFlight && session.stream.isActive()) session.abort();
|
|
@@ -872,6 +997,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
872
997
|
}));
|
|
873
998
|
if (await kickoffStale()) throw new FactoryDecisionSuperseded();
|
|
874
999
|
}
|
|
1000
|
+
const goal = decision.goal ? await this.#setPhaseGoal(record, decision.goal, session, binding) : void 0;
|
|
875
1001
|
const since = /* @__PURE__ */ new Date();
|
|
876
1002
|
const run = watchRun(session, {
|
|
877
1003
|
timeoutMs: this.#skillCompletionObservationTimeoutMs,
|
|
@@ -903,6 +1029,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
903
1029
|
run.arm();
|
|
904
1030
|
settled = await sendKickoff();
|
|
905
1031
|
}
|
|
1032
|
+
if (goal) await this.#remindPhaseGoal(record, goal, session, binding, requestContext);
|
|
906
1033
|
await this.#recordRunStart(session, binding, deliveryId, record.approvedBy ?? void 0, run.endReason, item?.title);
|
|
907
1034
|
this.#reviewWatched.add(record);
|
|
908
1035
|
await this.#reviewStatus(record, decision, {
|
|
@@ -981,7 +1108,22 @@ var FactoryDecisionDispatcher = class {
|
|
|
981
1108
|
return;
|
|
982
1109
|
case "notify": {
|
|
983
1110
|
const binding = await this.#requireBinding(record);
|
|
1111
|
+
const startedBy = (record.workItemId ? await this.#storage.get({
|
|
1112
|
+
orgId: record.orgId,
|
|
1113
|
+
id: record.workItemId
|
|
1114
|
+
}) : null)?.sessions[binding.role]?.startedBy;
|
|
1115
|
+
if (!startedBy) throw new Error(`Factory binding ${binding.id} has no authenticated session owner.`);
|
|
1116
|
+
await this.#primeCredentials?.({
|
|
1117
|
+
orgId: record.orgId,
|
|
1118
|
+
userId: startedBy
|
|
1119
|
+
});
|
|
984
1120
|
const session = await this.#requireSession(binding);
|
|
1121
|
+
const requestContext = factoryRequestContext({
|
|
1122
|
+
session,
|
|
1123
|
+
binding,
|
|
1124
|
+
userId: startedBy,
|
|
1125
|
+
orgId: record.orgId
|
|
1126
|
+
});
|
|
985
1127
|
await awaitNotification(() => session.sendNotificationSignal({
|
|
986
1128
|
source: "factory",
|
|
987
1129
|
kind: "rule-notification",
|
|
@@ -992,7 +1134,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
992
1134
|
},
|
|
993
1135
|
sourceId: record.id,
|
|
994
1136
|
dedupeKey: record.idempotencyKey
|
|
995
|
-
}));
|
|
1137
|
+
}, { requestContext }));
|
|
996
1138
|
}
|
|
997
1139
|
}
|
|
998
1140
|
}
|
|
@@ -1019,6 +1161,29 @@ var FactoryDecisionDispatcher = class {
|
|
|
1019
1161
|
factoryProjectId: record.factoryProjectId,
|
|
1020
1162
|
source: externalSourceForDecision(requested)
|
|
1021
1163
|
});
|
|
1164
|
+
if (existing && externalSourceKey(existing.externalSource) !== externalSourceKey(externalSourceForDecision(requested))) {
|
|
1165
|
+
const source = externalSourceForDecision(requested);
|
|
1166
|
+
const facts = workItemProviderAdapter(source).toSource(source, requested.metadata ?? null);
|
|
1167
|
+
if (facts?.state === "open") await this.#storage.syncWorkItemSource({
|
|
1168
|
+
orgId: record.orgId,
|
|
1169
|
+
factoryProjectId: record.factoryProjectId,
|
|
1170
|
+
provider: facts.provider,
|
|
1171
|
+
externalId: facts.externalId,
|
|
1172
|
+
patch: (current) => current.state === "closed" || current.state === "merged" ? {
|
|
1173
|
+
state: facts.state,
|
|
1174
|
+
metadata: {
|
|
1175
|
+
...current.metadata,
|
|
1176
|
+
...facts.metadata
|
|
1177
|
+
}
|
|
1178
|
+
} : null
|
|
1179
|
+
});
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (!existing && requested.attachTo) {
|
|
1183
|
+
const attachBoards = await this.#boards.load(record);
|
|
1184
|
+
if (await this.#attachLinkedItem(record, requested, requested.attachTo.workItemId, causalChain, (card) => cardBoardFlow(attachBoards, card).pullRequestReview !== void 0 ? { phase: null } : void 0)) return;
|
|
1185
|
+
}
|
|
1186
|
+
if (!existing && requested.closesIssue && await this.#joinClosedIssue(record, requested, causalChain)) return;
|
|
1022
1187
|
const materializedHere = existing?.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
|
|
1023
1188
|
if (materializedHere && requested.skipRules === true) return;
|
|
1024
1189
|
const boards = await this.#boards.load(record);
|
|
@@ -1066,7 +1231,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
1066
1231
|
reuseMode: "preserve"
|
|
1067
1232
|
});
|
|
1068
1233
|
const itemBoard = boardForWorkItem(result.item);
|
|
1069
|
-
const
|
|
1234
|
+
const itemFlow = itemBoard === decision.board ? void 0 : boardFlow(boards.get(itemBoard));
|
|
1235
|
+
const keptReview = isPullRequestCard({ source: workItemSource(result.item.externalSource) }) ? itemFlow?.pullRequestReview : void 0;
|
|
1236
|
+
const board = keptReview === void 0 ? decision.board : itemBoard;
|
|
1237
|
+
const placeStage = keptReview !== void 0 && decision.stage === boardFlow(definition).pullRequestReview ? keptReview : decision.stage;
|
|
1070
1238
|
if (!skipRules && itemBoard !== board) throw new Error(`The work item belongs to board "${itemBoard}", not "${board}".`);
|
|
1071
1239
|
if (!result.item.parentWorkItemId && parentWorkItemId && parentWorkItemId !== result.item.id) {
|
|
1072
1240
|
const item = await this.#storage.setParentWorkItemIfMissing({
|
|
@@ -1098,14 +1266,22 @@ var FactoryDecisionDispatcher = class {
|
|
|
1098
1266
|
}
|
|
1099
1267
|
}
|
|
1100
1268
|
if (skipRules) {
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1269
|
+
let item = result.created ? null : result.item;
|
|
1270
|
+
for (let attempt = 0; item && attempt < 3; attempt += 1) {
|
|
1271
|
+
if (await moveCardToBoard({
|
|
1272
|
+
workItems: this.#storage,
|
|
1273
|
+
boardRegistry: boards,
|
|
1274
|
+
userId: "factory-rule-dispatcher",
|
|
1275
|
+
item,
|
|
1276
|
+
targetBoard: board,
|
|
1277
|
+
targetStage: placeStage
|
|
1278
|
+
}) !== "skipped") break;
|
|
1279
|
+
const fresh = await this.#storage.get({
|
|
1280
|
+
orgId: record.orgId,
|
|
1281
|
+
id: item.id
|
|
1282
|
+
});
|
|
1283
|
+
item = fresh && fresh.revision !== item.revision ? fresh : null;
|
|
1284
|
+
}
|
|
1109
1285
|
return;
|
|
1110
1286
|
}
|
|
1111
1287
|
const materializedByDecision = result.item.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
|
|
@@ -1160,6 +1336,103 @@ var FactoryDecisionDispatcher = class {
|
|
|
1160
1336
|
if (moved.status === "rejected") throw new Error(`${moved.code}: ${moved.reason}`);
|
|
1161
1337
|
}
|
|
1162
1338
|
/**
|
|
1339
|
+
* Files a pull or merge request on the existing card `workItemId`, as one more source, when
|
|
1340
|
+
* `admit` takes the card as it is now; the card then moves to the phase `admit` names when its
|
|
1341
|
+
* board allows it. Returns false when the card can't take it (gone, finished, a pull request's
|
|
1342
|
+
* own card, refused by `admit`, or another card took the record first), so the caller files the
|
|
1343
|
+
* record as usual. `admit` runs again on a fresh read whenever the card changed in between.
|
|
1344
|
+
*/
|
|
1345
|
+
async #attachLinkedItem(record, decision, workItemId, causalChain, admit) {
|
|
1346
|
+
if (this.#storage.legacyMode) return false;
|
|
1347
|
+
const boards = await this.#boards.load(record);
|
|
1348
|
+
let attached;
|
|
1349
|
+
for (let attempt = 0; attempt < 3 && !attached; attempt++) {
|
|
1350
|
+
const card = await this.#storage.get({
|
|
1351
|
+
orgId: record.orgId,
|
|
1352
|
+
id: workItemId
|
|
1353
|
+
});
|
|
1354
|
+
if (!card || card.factoryProjectId !== record.factoryProjectId || isTerminalWorkItem(boards, card) || isPullRequestCard({ source: workItemSource(card.externalSource) })) return false;
|
|
1355
|
+
const admitted = admit(card);
|
|
1356
|
+
if (!admitted) return false;
|
|
1357
|
+
try {
|
|
1358
|
+
const result = await this.#storage.attachSource({
|
|
1359
|
+
orgId: record.orgId,
|
|
1360
|
+
id: card.id,
|
|
1361
|
+
source: externalSourceForDecision(decision),
|
|
1362
|
+
metadata: decision.metadata ?? null,
|
|
1363
|
+
expectedRevision: card.revision
|
|
1364
|
+
});
|
|
1365
|
+
if (!result) return false;
|
|
1366
|
+
attached = {
|
|
1367
|
+
card: result.item,
|
|
1368
|
+
phase: admitted.phase
|
|
1369
|
+
};
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
if (error instanceof WorkItemSourceConflictError) return false;
|
|
1372
|
+
if (error instanceof WorkItemUpdateConflictError) continue;
|
|
1373
|
+
throw error;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
if (!attached) return false;
|
|
1377
|
+
const { card, phase } = attached;
|
|
1378
|
+
const stage = card.stages.length === 1 ? card.stages[0] : void 0;
|
|
1379
|
+
const board = boards.get(boardForWorkItem(card));
|
|
1380
|
+
if (!phase || !stage || stage === phase) return true;
|
|
1381
|
+
if (!board?.allowsTransition(stage, phase)) {
|
|
1382
|
+
console.warn(`[factory] attached a pull request to ${card.id}, which stays in ${stage}: its board has no move to ${phase}`);
|
|
1383
|
+
return true;
|
|
1384
|
+
}
|
|
1385
|
+
const moved = await this.#transitionService.transition({
|
|
1386
|
+
orgId: record.orgId,
|
|
1387
|
+
factoryProjectId: record.factoryProjectId,
|
|
1388
|
+
workItemId: card.id,
|
|
1389
|
+
board: board.id,
|
|
1390
|
+
stage: phase,
|
|
1391
|
+
expectedRevision: card.revision,
|
|
1392
|
+
actor: {
|
|
1393
|
+
type: "system",
|
|
1394
|
+
id: "factory-rule-dispatcher"
|
|
1395
|
+
},
|
|
1396
|
+
ingress: {
|
|
1397
|
+
type: "rule",
|
|
1398
|
+
identity: `decision:${record.idempotencyKey}:${card.id}:attach`
|
|
1399
|
+
},
|
|
1400
|
+
cause: "linked_item_attached",
|
|
1401
|
+
causalChain
|
|
1402
|
+
});
|
|
1403
|
+
if (moved.status === "rejected") console.warn(`[factory] attached a pull request to ${card.id} but could not move it to ${phase}: ${moved.code}: ${moved.reason}`);
|
|
1404
|
+
return true;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Joins a pull or merge request to the card of the issue it closes when the project's intake
|
|
1408
|
+
* routes say so: the first route matching the arrival, with the facts of that card as it is now,
|
|
1409
|
+
* is a joining one. Only an arrival the routes would place qualifies, and only from an author
|
|
1410
|
+
* with write access: no route can put an outsider's pull request on someone else's card.
|
|
1411
|
+
*/
|
|
1412
|
+
async #joinClosedIssue(record, decision, causalChain) {
|
|
1413
|
+
if (!authorTrusted(decision.metadata) || !this.#intakeRoutes || decision.skipRules === true) return false;
|
|
1414
|
+
if (record.workItemId !== null) return false;
|
|
1415
|
+
const boards = await this.#boards.load(record);
|
|
1416
|
+
if (decision.stage !== boards.get(decision.board)?.initialPhase) return false;
|
|
1417
|
+
const routes = await this.#intakeRoutes.listIntakeRoutes({
|
|
1418
|
+
orgId: record.orgId,
|
|
1419
|
+
factoryProjectId: record.factoryProjectId
|
|
1420
|
+
});
|
|
1421
|
+
if (routes.length === 0) return false;
|
|
1422
|
+
const arrival = cardRuleFacts({
|
|
1423
|
+
title: decision.title,
|
|
1424
|
+
metadata: decision.metadata ?? {},
|
|
1425
|
+
externalSource: externalSourceForDecision(decision)
|
|
1426
|
+
});
|
|
1427
|
+
return this.#attachLinkedItem(record, decision, decision.closesIssue.workItemId, causalChain, (card) => {
|
|
1428
|
+
const route = resolveIntakeRoute(routes, {
|
|
1429
|
+
...arrival,
|
|
1430
|
+
...closedIssueRuleFacts(card)
|
|
1431
|
+
}, boards, card);
|
|
1432
|
+
return route?.type === "join" ? { phase: route.phase } : void 0;
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1163
1436
|
* Applies the project's intake routes to an arrival: a decision filing the card at its
|
|
1164
1437
|
* board's initial phase. A decision naming a later phase (a maintainer's review request)
|
|
1165
1438
|
* or placing the card outright (`skipRules`) already chose where the card goes.
|
|
@@ -1173,11 +1446,18 @@ var FactoryDecisionDispatcher = class {
|
|
|
1173
1446
|
factoryProjectId: record.factoryProjectId
|
|
1174
1447
|
});
|
|
1175
1448
|
if (routes.length === 0) return decision;
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1449
|
+
const closedIssue = decision.closesIssue ? await this.#storage.get({
|
|
1450
|
+
orgId: record.orgId,
|
|
1451
|
+
id: decision.closesIssue.workItemId
|
|
1452
|
+
}) : null;
|
|
1453
|
+
const facts = {
|
|
1454
|
+
...cardRuleFacts({
|
|
1455
|
+
title: decision.title,
|
|
1456
|
+
metadata: decision.metadata ?? {},
|
|
1457
|
+
externalSource: externalSourceForDecision(decision)
|
|
1458
|
+
}),
|
|
1459
|
+
...decision.closesIssue ? closedIssueRuleFacts(closedIssue && closedIssue.factoryProjectId === record.factoryProjectId && !isTerminalWorkItem(boards, closedIssue) ? closedIssue : void 0) : {}
|
|
1460
|
+
};
|
|
1181
1461
|
const placement = resolveIntakePlacement(routes, facts, boards);
|
|
1182
1462
|
if (!placement) return decision;
|
|
1183
1463
|
return {
|
|
@@ -1318,7 +1598,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1318
1598
|
if (!board) return void 0;
|
|
1319
1599
|
const stage = item.stages.length === 1 ? item.stages[0] : void 0;
|
|
1320
1600
|
const finished = stage !== void 0 && board.isTerminal(stage);
|
|
1321
|
-
if (event.type
|
|
1601
|
+
if (!eventMovesCard(event.type, finished)) return void 0;
|
|
1322
1602
|
const routes = this.#intakeRoutes ? await this.#intakeRoutes.listIntakeRoutes({
|
|
1323
1603
|
orgId: record.orgId,
|
|
1324
1604
|
factoryProjectId: record.factoryProjectId
|
|
@@ -1328,8 +1608,18 @@ var FactoryDecisionDispatcher = class {
|
|
|
1328
1608
|
board,
|
|
1329
1609
|
fallback: true
|
|
1330
1610
|
};
|
|
1331
|
-
const route = resolveEventRoute(routes, event, cardRuleFacts(item), board);
|
|
1332
|
-
if (!route
|
|
1611
|
+
const route = resolveEventRoute(routes, event, cardRuleFacts(item), board, hasPullRequest(item));
|
|
1612
|
+
if (!route) return fallback && isPullRequestEvent(event.type) ? {
|
|
1613
|
+
item,
|
|
1614
|
+
board,
|
|
1615
|
+
fallback: true
|
|
1616
|
+
} : void 0;
|
|
1617
|
+
if (fallback && isPullRequestEvent(event.type) && route.phase === fallback.stage) return {
|
|
1618
|
+
item,
|
|
1619
|
+
board,
|
|
1620
|
+
fallback: true
|
|
1621
|
+
};
|
|
1622
|
+
if (stage === route.phase) return void 0;
|
|
1333
1623
|
return {
|
|
1334
1624
|
item,
|
|
1335
1625
|
board,
|
|
@@ -1378,7 +1668,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1378
1668
|
* millisecond, the one with the greatest id is the last; one already settled had its turn.
|
|
1379
1669
|
*/
|
|
1380
1670
|
async #statusEventOvertaken(record) {
|
|
1381
|
-
if (!record.workItemId) return false;
|
|
1671
|
+
if (!record.workItemId || !isStatusEventDecision(record.decision)) return false;
|
|
1382
1672
|
return (await this.#storage.listDeferredDecisions(record.orgId, record.factoryProjectId, { workItemId: record.workItemId })).some((other) => other.id !== record.id && isStatusEventDecision(other.decision) && (other.createdAt.getTime() > record.createdAt.getTime() || other.createdAt.getTime() === record.createdAt.getTime() && other.completedAt === null && other.id > record.id));
|
|
1383
1673
|
}
|
|
1384
1674
|
async #requireItem(record) {
|
|
@@ -1392,9 +1682,18 @@ var FactoryDecisionDispatcher = class {
|
|
|
1392
1682
|
}
|
|
1393
1683
|
async #findBinding(record, role) {
|
|
1394
1684
|
if (!record.workItemId) throw new Error("Factory decision is not linked to a work item.");
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1685
|
+
const active = (await this.#storage.listRunBindings(record.orgId, record.factoryProjectId, record.workItemId)).filter((candidate) => candidate.status === "active" && (role === void 0 || candidate.role === role));
|
|
1686
|
+
let builder;
|
|
1687
|
+
if (role === void 0 && active.length > 1) {
|
|
1688
|
+
const item = await this.#storage.get({
|
|
1689
|
+
orgId: record.orgId,
|
|
1690
|
+
id: record.workItemId
|
|
1691
|
+
});
|
|
1692
|
+
builder = item ? cardBoardFlow(await this.#boards.load(record), item).buildRole : void 0;
|
|
1693
|
+
}
|
|
1694
|
+
return active.sort((left, right) => {
|
|
1695
|
+
if (builder !== void 0 && left.role === builder && right.role !== builder) return -1;
|
|
1696
|
+
if (builder !== void 0 && right.role === builder && left.role !== builder) return 1;
|
|
1398
1697
|
return right.createdAt.getTime() - left.createdAt.getTime() || left.id.localeCompare(right.id);
|
|
1399
1698
|
})[0];
|
|
1400
1699
|
}
|
|
@@ -1760,8 +2059,7 @@ const FACTORY_DISPATCH_CONSTANTS = {
|
|
|
1760
2059
|
runRegistryHeartbeatMs: RUN_REGISTRY_HEARTBEAT_MS,
|
|
1761
2060
|
openRunStaleMs: FACTORY_OPEN_RUN_STALE_MS,
|
|
1762
2061
|
maxInFlight: MAX_IN_FLIGHT,
|
|
1763
|
-
reviewStatusTimeoutMs: REVIEW_STATUS_TIMEOUT_MS
|
|
1764
|
-
stages: FACTORY_RULE_STAGES
|
|
2062
|
+
reviewStatusTimeoutMs: REVIEW_STATUS_TIMEOUT_MS
|
|
1765
2063
|
};
|
|
1766
2064
|
export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher };
|
|
1767
2065
|
|