@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-tools.js","names":[],"sources":["../../src/tools/work-item-tools.ts"],"sourcesContent":["/**\n * Factory tools that change work items: file one, move it, settle its\n * decisions, and follow it. They act as the session's person (a human actor),\n * through the same code the board's routes use.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { boardForWorkItem } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { IntakeRoutesReader } from '../boards/intake-routing.js';\nimport { toBoardSource } from '../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../boards/project-boards.js';\nimport type { IntegrationTools } from '../integrations/base.js';\nimport { factoryWorkItemUrl } from '../links.js';\nimport { transitionBodySchema } from '../routes/contracts.js';\nimport type { FactoryTransitionService } from '../rules/transition-service.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport { WorkItemRelationError } from '../storage/domains/work-items/base.js';\nimport type { UpdateWorkItemInput, Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { workItemNumber } from '../work-items/card-number.js';\nimport { createFactoryWorkItem } from '../work-items/create-work-item.js';\nimport type { FactoryAuditEmit } from '../work-items/create-work-item.js';\nimport {\n dismissFactoryDecision,\n resolveFactoryProposal,\n retryFactoryDecision,\n} from '../work-items/decision-actions.js';\nimport type { FactoryDecisionActionResult } from '../work-items/decision-actions.js';\nimport { MAX_TEXT, findWorkItem, workItemRefSchema, truncate, workItemNotFound, workItemStage } from './read-tools.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryWorkItemToolDependencies {\n workItems: WorkItemsStorage;\n /** A fixed registry, or the per-project boards. */\n boards: BoardRegistry | ProjectBoardSource;\n /** The project's intake routes, which place a filed card. */\n intakeRoutes?: IntakeRoutesReader;\n /** Governed stage moves; filing and moving items refuse while it is unavailable. */\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n /** Writes audit rows with an explicit actor; tool calls have no HTTP request to read one from. */\n auditRecorder: AuditRecorder;\n /** Finds the caller session's source-control provider, whose linked repositories a card can name. */\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n}\n\nconst repositorySchema = z\n .string()\n .trim()\n .min(3)\n .max(200)\n .regex(/^[^/\\s]+\\/[^/\\s]+$/, 'Use the owner/name form, e.g. \"mastra-ai/mastra\".')\n .describe('A repository linked to this Factory, as owner/name.');\n\nconst decisionId = z.string().trim().uuid().describe('Decision id, from factory_list_attention or inspect.');\n\nfunction briefItem(item: Card) {\n return {\n id: item.id,\n number: workItemNumber(item),\n title: truncate(item.title, MAX_TEXT),\n stage: workItemStage(item),\n url:\n factoryWorkItemUrl({\n factoryProjectId: item.factoryProjectId,\n board: boardForWorkItem(item),\n workItemId: item.id,\n }) ?? null,\n };\n}\n\nfunction settled(result: FactoryDecisionActionResult) {\n if (!result.ok) throw new Error(result.message);\n const { decision } = result;\n return { decisionId: decision.id, status: decision.status, workItemId: decision.workItemId };\n}\n\n/** The work-item write and subscription tools for one user session's turn. */\nexport function createFactoryWorkItemTools(\n scope: FactoryToolScope,\n deps: FactoryWorkItemToolDependencies,\n): IntegrationTools {\n const project = { orgId: scope.orgId, factoryProjectId: scope.factoryProjectId };\n const audit: FactoryAuditEmit = async input => {\n await deps.auditRecorder.record({\n orgId: scope.orgId,\n // Turns nobody signed in started are recorded as this session's agent, as their moves are.\n actorId: scope.interactive ? scope.userId : `agent:session:${scope.sessionId}`,\n actorType: scope.interactive ? 'human' : 'agent',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ...input,\n });\n };\n const requireItem = async (ref: string) => {\n const item = await findWorkItem(deps.workItems, scope, ref);\n if (!item) throw workItemNotFound(ref);\n return item;\n };\n /**\n * Check `slug` is a repository linked to this Factory and that a card with\n * `metadata` would run in it (a card synced from an issue follows the\n * issue's repository, which a slug can't override).\n */\n const requireRepository = async (slug: string, item?: Pick<Card, 'metadata' | 'workItem'>) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no source-control provider to look repositories up in.');\n const resolve = (repository?: string) =>\n resolveWorkItemRepository({\n sourceControl,\n ...project,\n item: {\n metadata: repository ? { repository } : (item?.metadata ?? null),\n workItem: item?.workItem ?? { metadata: null },\n },\n });\n const resolution = await resolve(slug);\n if (resolution.status === 'resolved' && resolution.slug === slug) return;\n if (resolution.status === 'resolved') {\n throw new Error(`This card runs in ${resolution.slug}, which comes from its linked issue and can't be changed.`);\n }\n const linked = await resolve();\n const candidates =\n linked.status === 'ambiguous' ? linked.candidates : linked.status === 'resolved' ? [linked.slug] : [];\n throw new Error(\n candidates.length > 0\n ? `${slug} is not linked to this Factory. Linked repositories: ${candidates.join(', ')}.`\n : `${slug} is not linked to this Factory, and it has no linked repositories.`,\n );\n };\n const follow = (item: Card, reason: 'created' | 'moved' | 'subscribed') =>\n deps.workItems.subscribeToWorkItem({\n ...project,\n workItemId: item.id,\n sessionId: scope.sessionId,\n threadId: scope.threadId,\n resourceId: scope.resourceId,\n userId: scope.userId,\n reason,\n });\n\n return {\n factory_create_work_item: createTool({\n id: 'factory_create_work_item',\n description:\n \"File a new work item on this Factory's Work board (or wherever the project's intake routes send it) for the person you are working with. It enters its board's first phase, or the phase an intake route names, and this session follows it. Check factory_list_work_items for an existing item first. Name the repository when the Factory links more than one; runs refuse to start on a card that doesn't say which.\",\n inputSchema: z\n .object({\n title: z.string().trim().min(1).max(512).describe('Short title, as it should read on the card.'),\n description: z\n .string()\n .trim()\n .min(1)\n .max(8000)\n .describe('What needs doing and why; becomes the card description its runs start from.'),\n repository: repositorySchema.optional(),\n })\n .strict(),\n execute: async ({ title, description, repository }) => {\n if (repository) await requireRepository(repository);\n const created = await createFactoryWorkItem({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n transitionService: deps.transitionService,\n intakeRoutes: deps.intakeRoutes,\n audit,\n ...project,\n userId: scope.userId,\n ...(scope.actorProfile ? { origin: { actorProfile: scope.actorProfile } } : {}),\n input: { title, description, ...(repository ? { metadata: { repository } } : {}) },\n });\n if (created.status === 'refused') throw new Error(created.message);\n if (created.status === 'rejected') throw new Error(`The board refused the new item: ${created.reason}`);\n const { item } = created;\n // The card exists from here on: report follow-up failures alongside it\n // rather than failing the call, so the agent doesn't file it twice.\n const warnings: string[] = [];\n try {\n await follow(item, 'created');\n } catch (error) {\n warnings.push(\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n return warnings.length ? { ...briefItem(item), warnings } : briefItem(item);\n },\n }),\n\n factory_transition_work_item: createTool({\n id: 'factory_transition_work_item',\n description:\n \"Move a work item to another stage of its board, as the person you are working with. The board's rules decide whether the move is allowed and what it starts.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n stage: z.string().trim().min(1).max(64).describe('Destination stage, e.g. \"planning\" or \"done\".'),\n })\n .strict(),\n execute: async ({ workItem, stage }) => {\n if (!deps.transitionService) throw new Error('Factory stage transitions are not available right now.');\n const item = await requireItem(workItem);\n const parsed = transitionBodySchema.safeParse({\n board: boardForWorkItem(item),\n stage,\n expectedRevision: item.revision,\n requestId: randomUUID(),\n cause: 'factory_tools',\n });\n if (!parsed.success) throw new Error(`\"${stage}\" is not a valid stage name.`);\n const result = await deps.transitionService.transition({\n ...parsed.data,\n ...project,\n workItemId: item.id,\n ...(scope.interactive\n ? {\n actor: { type: 'human' as const, id: scope.userId },\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ingress: { ...parsed.data.ingress, identity: `human:${scope.userId}:${parsed.data.ingress.identity}` },\n }\n : {\n // Nobody signed in started this turn: move as this session's agent, so the\n // plan gate and the agent's done gates apply and the move arms no runs.\n actor: { type: 'agent' as const, bindingId: `session:${scope.sessionId}`, role: 'session' },\n ingress: {\n type: 'agent' as const,\n identity: `session:${scope.sessionId}:${parsed.data.ingress.identity}`,\n },\n }),\n });\n if (result.status === 'rejected') throw new Error(`The move was refused (${result.code}): ${result.reason}`);\n // The move can start a phase session the Factory owns. Following the card is what lets\n // this session hear when that run waits on someone, and answer it from here.\n // The card has moved by now: a failed follow is reported with the move, not instead of it.\n const moved = { workItemId: item.id, stage: result.stage, revision: result.revision };\n try {\n await follow(item, 'moved');\n } catch (error) {\n return {\n ...moved,\n warnings: [\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n ],\n };\n }\n return moved;\n },\n }),\n\n factory_update_work_item: createTool({\n id: 'factory_update_work_item',\n description:\n \"Edit a work item's fields as the person you are working with: its title, description, the repository its runs use, or its parent item. Move stages with factory_transition_work_item and start roles with factory_start_session.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n title: z.string().trim().min(1).max(500).optional().describe('New card title.'),\n description: z\n .string()\n .trim()\n .max(8000)\n .optional()\n .describe('New card description; an empty string clears it.'),\n repository: repositorySchema.optional(),\n parentWorkItem: workItemRefSchema\n .nullable()\n .optional()\n .describe('Parent work item (id or #number), or null to detach it from its parent.'),\n })\n .strict()\n .refine(input => Object.keys(input).some(key => key !== 'workItem'), 'Pass at least one field to change.'),\n execute: async ({ workItem, title, description, repository, parentWorkItem }) => {\n const item = await requireItem(workItem);\n if (repository) await requireRepository(repository, item);\n let parentWorkItemId: string | null | undefined;\n if (parentWorkItem === null) parentWorkItemId = null;\n else if (parentWorkItem !== undefined) parentWorkItemId = (await requireItem(parentWorkItem)).id;\n const patch: UpdateWorkItemInput = {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description: description || null } : {}),\n ...(repository ? { metadata: { repository } } : {}),\n ...(parentWorkItemId !== undefined ? { parentWorkItemId } : {}),\n };\n let updated: Awaited<ReturnType<WorkItemsStorage['update']>>;\n try {\n updated = await deps.workItems.update({ orgId: scope.orgId, id: item.id, userId: scope.userId, patch });\n } catch (error) {\n if (error instanceof WorkItemRelationError) throw new Error(`The parent was refused: ${error.message}`);\n throw error;\n }\n if (!updated) throw workItemNotFound(workItem);\n const fields = [\n ...(title !== undefined ? ['title'] : []),\n ...(description !== undefined ? ['description'] : []),\n ...(repository ? ['metadata'] : []),\n ...(parentWorkItemId !== undefined ? ['parentWorkItemId'] : []),\n ];\n await audit({\n action: 'factory.work_item.updated',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'work_item', id: updated.item.id, name: updated.item.title }],\n metadata: { fields, cause: 'factory_tools' },\n });\n const metadata = updated.item.metadata ?? {};\n return {\n workItem: briefItem(updated.item),\n updated: fields.map(field => (field === 'metadata' ? 'repository' : field)),\n repository: typeof metadata.repository === 'string' ? metadata.repository : null,\n parentWorkItemId: updated.item.parentWorkItemId,\n };\n },\n }),\n\n factory_retry_decision: createTool({\n id: 'factory_retry_decision',\n description:\n 'Retry one failed Factory run once its cause is fixed. Refused when the failure cannot be fixed by retrying or the item has moved on.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) =>\n settled(\n await retryFactoryDecision({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n ...project,\n decisionId,\n }),\n ),\n }),\n\n factory_dismiss_decision: createTool({\n id: 'factory_dismiss_decision',\n description: 'Dismiss one proposed Factory run that is no longer wanted.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) => {\n requirePerson(scope, 'dismiss a proposed run');\n return settled(\n await dismissFactoryDecision({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n }),\n );\n },\n }),\n\n factory_resolve_proposal: createTool({\n id: 'factory_resolve_proposal',\n description:\n \"Approve or dismiss one proposed Factory run. Approving starts the run and lets the item's later runs start without asking.\",\n inputSchema: z.object({ decisionId, action: z.enum(['approve', 'dismiss']) }).strict(),\n execute: async ({ decisionId, action }) => {\n requirePerson(scope, 'approve or dismiss a proposed run');\n return settled(\n await resolveFactoryProposal({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n action,\n }),\n );\n },\n }),\n\n factory_subscribe_work_item: createTool({\n id: 'factory_subscribe_work_item',\n description:\n 'Follow a work item from this session, so you hear about its progress and its sessions report to you. Items you file or start are followed already.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const subscription = await follow(item, 'subscribed');\n return { workItem: briefItem(item), subscribed: true, reason: subscription.reason };\n },\n }),\n\n factory_unsubscribe_work_item: createTool({\n id: 'factory_unsubscribe_work_item',\n description: 'Stop following a work item from this session.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const removed = await deps.workItems.unsubscribeFromWorkItem({\n orgId: scope.orgId,\n workItemId: item.id,\n sessionId: scope.sessionId,\n });\n return { workItem: briefItem(item), subscribed: false, wasSubscribed: removed };\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,mBAAmB,EACtB,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,sBAAsB,qDAAmD,CAAC,CAChF,SAAS,qDAAqD;AAEjE,MAAM,aAAa,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,sDAAsD;AAE3G,SAAS,UAAU,MAAY;CAC7B,OAAO;EACL,IAAI,KAAK;EACT,QAAQ,eAAe,IAAI;EAC3B,OAAO,SAAS,KAAK,OAAA,GAAe;EACpC,OAAO,cAAc,IAAI;EACzB,KACE,mBAAmB;GACjB,kBAAkB,KAAK;GACvB,OAAO,iBAAiB,IAAI;GAC5B,YAAY,KAAK;EACnB,CAAC,KAAK;CACV;AACF;AAEA,SAAS,QAAQ,QAAqC;CACpD,IAAI,CAAC,OAAO,IAAI,MAAM,IAAI,MAAM,OAAO,OAAO;CAC9C,MAAM,EAAE,aAAa;CACrB,OAAO;EAAE,YAAY,SAAS;EAAI,QAAQ,SAAS;EAAQ,YAAY,SAAS;CAAW;AAC7F;;AAGA,SAAgB,2BACd,OACA,MACkB;CAClB,MAAM,UAAU;EAAE,OAAO,MAAM;EAAO,kBAAkB,MAAM;CAAiB;CAC/E,MAAM,QAA0B,OAAM,UAAS;EAC7C,MAAM,KA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,OAAO;KAAE,UAAU,UAAU,IAAI;KAAG,YAAY;KAAO,eAAe;IAAQ;GAChF;EACF,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"work-item-tools.js","names":[],"sources":["../../src/tools/work-item-tools.ts"],"sourcesContent":["/**\n * Factory tools that change work items: file one, move it, settle its\n * decisions, and follow it. They act as the session's person (a human actor),\n * through the same code the board's routes use.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { boardForWorkItem } from '../boards/index.js';\n\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { IntakeRoutesReader } from '../boards/intake-routing.js';\nimport { toBoardSource } from '../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../boards/project-boards.js';\nimport type { IntegrationTools } from '../integrations/base.js';\nimport { factoryWorkItemUrl } from '../links.js';\nimport { transitionBodySchema } from '../routes/contracts.js';\nimport type { FactoryTransitionService } from '../rules/transition-service.js';\nimport { MAX_BOARD_IDENTIFIER_LENGTH } from '../rules/validation.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { IntakeEvaluator } from '../storage/domains/boards/base.js';\nimport { WorkItemRelationError } from '../storage/domains/work-items/base.js';\nimport type { UpdateWorkItemInput, Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { workItemNumber } from '../work-items/card-number.js';\nimport { createFactoryWorkItem } from '../work-items/create-work-item.js';\nimport type { FactoryAuditEmit } from '../work-items/create-work-item.js';\nimport {\n dismissFactoryDecision,\n resolveFactoryProposal,\n retryFactoryDecision,\n} from '../work-items/decision-actions.js';\nimport type { FactoryDecisionActionResult } from '../work-items/decision-actions.js';\nimport { MAX_TEXT, findWorkItem, workItemRefSchema, truncate, workItemNotFound, workItemStage } from './read-tools.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryWorkItemToolDependencies {\n workItems: WorkItemsStorage;\n /** A fixed registry, or the per-project boards. */\n boards: BoardRegistry | ProjectBoardSource;\n /** The project's intake routes, which place a filed card. */\n intakeRoutes?: IntakeRoutesReader;\n /** Which evaluator places a filed card; the old `route-list` by default. */\n intakeEvaluator?: IntakeEvaluator;\n /** Governed stage moves; filing and moving items refuse while it is unavailable. */\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n /** Writes audit rows with an explicit actor; tool calls have no HTTP request to read one from. */\n auditRecorder: AuditRecorder;\n /** Finds the caller session's source-control provider, whose linked repositories a card can name. */\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n}\n\nconst repositorySchema = z\n .string()\n .trim()\n .min(3)\n .max(200)\n .regex(/^[^/\\s]+\\/[^/\\s]+$/, 'Use the owner/name form, e.g. \"mastra-ai/mastra\".')\n .describe('A repository linked to this Factory, as owner/name.');\n\nconst decisionId = z.string().trim().uuid().describe('Decision id, from factory_list_attention or inspect.');\n\nfunction briefItem(item: Card) {\n return {\n id: item.id,\n number: workItemNumber(item),\n title: truncate(item.title, MAX_TEXT),\n stage: workItemStage(item),\n url:\n factoryWorkItemUrl({\n factoryProjectId: item.factoryProjectId,\n board: boardForWorkItem(item),\n workItemId: item.id,\n }) ?? null,\n };\n}\n\nfunction settled(result: FactoryDecisionActionResult) {\n if (!result.ok) throw new Error(result.message);\n const { decision } = result;\n return { decisionId: decision.id, status: decision.status, workItemId: decision.workItemId };\n}\n\n/** The work-item write and subscription tools for one user session's turn. */\nexport function createFactoryWorkItemTools(\n scope: FactoryToolScope,\n deps: FactoryWorkItemToolDependencies,\n): IntegrationTools {\n const project = { orgId: scope.orgId, factoryProjectId: scope.factoryProjectId };\n const audit: FactoryAuditEmit = async input => {\n await deps.auditRecorder.record({\n orgId: scope.orgId,\n // Turns nobody signed in started are recorded as this session's agent, as their moves are.\n actorId: scope.interactive ? scope.userId : `agent:session:${scope.sessionId}`,\n actorType: scope.interactive ? 'human' : 'agent',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ...input,\n });\n };\n const requireItem = async (ref: string) => {\n const item = await findWorkItem(deps.workItems, scope, ref);\n if (!item) throw workItemNotFound(ref);\n return item;\n };\n /**\n * Check `slug` is a repository linked to this Factory and that a card with\n * `metadata` would run in it (a card synced from an issue follows the\n * issue's repository, which a slug can't override).\n */\n const requireRepository = async (slug: string, item?: Pick<Card, 'metadata' | 'workItem'>) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no source-control provider to look repositories up in.');\n const resolve = (repository?: string) =>\n resolveWorkItemRepository({\n sourceControl,\n ...project,\n item: {\n metadata: repository ? { repository } : (item?.metadata ?? null),\n workItem: item?.workItem ?? { metadata: null },\n },\n });\n const resolution = await resolve(slug);\n if (resolution.status === 'resolved' && resolution.slug === slug) return;\n if (resolution.status === 'resolved') {\n throw new Error(`This card runs in ${resolution.slug}, which comes from its linked issue and can't be changed.`);\n }\n const linked = await resolve();\n const candidates =\n linked.status === 'ambiguous' ? linked.candidates : linked.status === 'resolved' ? [linked.slug] : [];\n throw new Error(\n candidates.length > 0\n ? `${slug} is not linked to this Factory. Linked repositories: ${candidates.join(', ')}.`\n : `${slug} is not linked to this Factory, and it has no linked repositories.`,\n );\n };\n const follow = (item: Card, reason: 'created' | 'moved' | 'subscribed') =>\n deps.workItems.subscribeToWorkItem({\n ...project,\n workItemId: item.id,\n sessionId: scope.sessionId,\n threadId: scope.threadId,\n resourceId: scope.resourceId,\n userId: scope.userId,\n reason,\n });\n\n return {\n factory_create_work_item: createTool({\n id: 'factory_create_work_item',\n description:\n \"File a new work item on this Factory for the person you are working with, on the board the project's intake rules pick (or the board named). It enters its board's first phase, or the phase an intake rule names, and this session follows it. Check factory_list_work_items for an existing item first. When no intake rule takes it, the call is refused: ask the person which board it belongs on and call again with that board. Name the repository when you know it; a run on a card that names none determines it from the card.\",\n inputSchema: z\n .object({\n title: z.string().trim().min(1).max(512).describe('Short title, as it should read on the card.'),\n description: z\n .string()\n .trim()\n .min(1)\n .max(8000)\n .describe('What needs doing and why; becomes the card description its runs start from.'),\n repository: repositorySchema.optional(),\n board: z\n .string()\n .trim()\n .min(1)\n .max(MAX_BOARD_IDENTIFIER_LENGTH)\n .optional()\n .describe(\"The board's key, when the person picked one; files it in that board's first phase.\"),\n })\n .strict(),\n execute: async ({ title, description, repository, board }) => {\n if (repository) await requireRepository(repository);\n const created = await createFactoryWorkItem({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n transitionService: deps.transitionService,\n intakeRoutes: deps.intakeRoutes,\n intakeEvaluator: deps.intakeEvaluator,\n audit,\n ...project,\n userId: scope.userId,\n ...(scope.actorProfile ? { origin: { actorProfile: scope.actorProfile } } : {}),\n input: {\n title,\n description,\n ...(board ? { board } : {}),\n ...(repository ? { metadata: { repository } } : {}),\n },\n });\n if (created.status === 'refused') throw new Error(created.message);\n if (created.status === 'rejected') throw new Error(`The board refused the new item: ${created.reason}`);\n const { item } = created;\n // The card exists from here on: report follow-up failures alongside it\n // rather than failing the call, so the agent doesn't file it twice.\n const warnings: string[] = [];\n try {\n await follow(item, 'created');\n } catch (error) {\n warnings.push(\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n return warnings.length ? { ...briefItem(item), warnings } : briefItem(item);\n },\n }),\n\n factory_transition_work_item: createTool({\n id: 'factory_transition_work_item',\n description:\n \"Move a work item to another stage of its board, as the person you are working with. The board's rules decide whether the move is allowed and what it starts.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n stage: z.string().trim().min(1).max(64).describe('Destination stage, e.g. \"planning\" or \"done\".'),\n })\n .strict(),\n execute: async ({ workItem, stage }) => {\n if (!deps.transitionService) throw new Error('Factory stage transitions are not available right now.');\n const item = await requireItem(workItem);\n const parsed = transitionBodySchema.safeParse({\n board: boardForWorkItem(item),\n stage,\n expectedRevision: item.revision,\n requestId: randomUUID(),\n cause: 'factory_tools',\n });\n if (!parsed.success) throw new Error(`\"${stage}\" is not a valid stage name.`);\n const result = await deps.transitionService.transition({\n ...parsed.data,\n ...project,\n workItemId: item.id,\n ...(scope.interactive\n ? {\n actor: { type: 'human' as const, id: scope.userId },\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ingress: { ...parsed.data.ingress, identity: `human:${scope.userId}:${parsed.data.ingress.identity}` },\n }\n : {\n // Nobody signed in started this turn: move as this session's agent, so the\n // plan gate and the agent's done gates apply and the move arms no runs.\n actor: { type: 'agent' as const, bindingId: `session:${scope.sessionId}`, role: 'session' },\n ingress: {\n type: 'agent' as const,\n identity: `session:${scope.sessionId}:${parsed.data.ingress.identity}`,\n },\n }),\n });\n if (result.status === 'rejected') throw new Error(`The move was refused (${result.code}): ${result.reason}`);\n // The move can start a phase session the Factory owns. Following the card is what lets\n // this session hear when that run waits on someone, and answer it from here.\n // The card has moved by now: a failed follow is reported with the move, not instead of it.\n const moved = { workItemId: item.id, stage: result.stage, revision: result.revision };\n try {\n await follow(item, 'moved');\n } catch (error) {\n return {\n ...moved,\n warnings: [\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n ],\n };\n }\n return moved;\n },\n }),\n\n factory_update_work_item: createTool({\n id: 'factory_update_work_item',\n description:\n \"Edit a work item's fields as the person you are working with: its title, description, the repository its runs use, or its parent item. Move stages with factory_transition_work_item and start roles with factory_start_session.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n title: z.string().trim().min(1).max(500).optional().describe('New card title.'),\n description: z\n .string()\n .trim()\n .max(8000)\n .optional()\n .describe('New card description; an empty string clears it.'),\n repository: repositorySchema.optional(),\n parentWorkItem: workItemRefSchema\n .nullable()\n .optional()\n .describe('Parent work item (id or #number), or null to detach it from its parent.'),\n })\n .strict()\n .refine(input => Object.keys(input).some(key => key !== 'workItem'), 'Pass at least one field to change.'),\n execute: async ({ workItem, title, description, repository, parentWorkItem }) => {\n const item = await requireItem(workItem);\n if (repository) await requireRepository(repository, item);\n let parentWorkItemId: string | null | undefined;\n if (parentWorkItem === null) parentWorkItemId = null;\n else if (parentWorkItem !== undefined) parentWorkItemId = (await requireItem(parentWorkItem)).id;\n const patch: UpdateWorkItemInput = {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description: description || null } : {}),\n ...(repository ? { metadata: { repository } } : {}),\n ...(parentWorkItemId !== undefined ? { parentWorkItemId } : {}),\n };\n let updated: Awaited<ReturnType<WorkItemsStorage['update']>>;\n try {\n updated = await deps.workItems.update({ orgId: scope.orgId, id: item.id, userId: scope.userId, patch });\n } catch (error) {\n if (error instanceof WorkItemRelationError) throw new Error(`The parent was refused: ${error.message}`);\n throw error;\n }\n if (!updated) throw workItemNotFound(workItem);\n const fields = [\n ...(title !== undefined ? ['title'] : []),\n ...(description !== undefined ? ['description'] : []),\n ...(repository ? ['metadata'] : []),\n ...(parentWorkItemId !== undefined ? ['parentWorkItemId'] : []),\n ];\n await audit({\n action: 'factory.work_item.updated',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'work_item', id: updated.item.id, name: updated.item.title }],\n metadata: { fields, cause: 'factory_tools' },\n });\n const metadata = updated.item.metadata ?? {};\n return {\n workItem: briefItem(updated.item),\n updated: fields.map(field => (field === 'metadata' ? 'repository' : field)),\n repository: typeof metadata.repository === 'string' ? metadata.repository : null,\n parentWorkItemId: updated.item.parentWorkItemId,\n };\n },\n }),\n\n factory_retry_decision: createTool({\n id: 'factory_retry_decision',\n description:\n 'Retry one failed Factory run once its cause is fixed. Refused when the failure cannot be fixed by retrying or the item has moved on.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) =>\n settled(\n await retryFactoryDecision({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n ...project,\n decisionId,\n }),\n ),\n }),\n\n factory_dismiss_decision: createTool({\n id: 'factory_dismiss_decision',\n description: 'Dismiss one proposed Factory run that is no longer wanted.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) => {\n requirePerson(scope, 'dismiss a proposed run');\n return settled(\n await dismissFactoryDecision({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n }),\n );\n },\n }),\n\n factory_resolve_proposal: createTool({\n id: 'factory_resolve_proposal',\n description:\n \"Approve or dismiss one proposed Factory run. Approving starts the run and lets the item's later runs start without asking.\",\n inputSchema: z.object({ decisionId, action: z.enum(['approve', 'dismiss']) }).strict(),\n execute: async ({ decisionId, action }) => {\n requirePerson(scope, 'approve or dismiss a proposed run');\n return settled(\n await resolveFactoryProposal({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n action,\n }),\n );\n },\n }),\n\n factory_subscribe_work_item: createTool({\n id: 'factory_subscribe_work_item',\n description:\n 'Follow a work item from this session, so you hear about its progress and its sessions report to you. Items you file or start are followed already.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const subscription = await follow(item, 'subscribed');\n return { workItem: briefItem(item), subscribed: true, reason: subscription.reason };\n },\n }),\n\n factory_unsubscribe_work_item: createTool({\n id: 'factory_unsubscribe_work_item',\n description: 'Stop following a work item from this session.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const removed = await deps.workItems.unsubscribeFromWorkItem({\n orgId: scope.orgId,\n workItemId: item.id,\n sessionId: scope.sessionId,\n });\n return { workItem: briefItem(item), subscribed: false, wasSubscribed: removed };\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,mBAAmB,EACtB,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,sBAAsB,qDAAmD,CAAC,CAChF,SAAS,qDAAqD;AAEjE,MAAM,aAAa,EAAE,OAAO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CAAC,WAAW,SAAS,CAAC;GAAE,CAAC,CAAC,CAAC,OAAO;GACrF,SAAS,OAAO,EAAE,YAAY,aAAa;IACzC,cAAc,OAAO,mCAAmC;IACxD,OAAO,QACL,MAAM,uBAAuB;KAC3B,WAAW,KAAK;KAChB;KACA,GAAG;KACH,QAAQ,MAAM;KACd;KACA;IACF,CAAC,CACH;GACF;EACF,CAAC;EAED,6BAA6B,WAAW;GACtC,IAAI;GACJ,aACE;GACF,aAAa,EAAE,OAAO,EAAE,UAAU,kBAAkB,CAAC,CAAC,CAAC,OAAO;GAC9D,SAAS,OAAO,EAAE,eAAe;IAC/B,MAAM,OAAO,MAAM,YAAY,QAAQ;IACvC,MAAM,eAAe,MAAM,OAAO,MAAM,YAAY;IACpD,OAAO;KAAE,UAAU,UAAU,IAAI;KAAG,YAAY;KAAM,QAAQ,aAAa;IAAO;GACpF;EACF,CAAC;EAED,+BAA+B,WAAW;GACxC,IAAI;GACJ,aAAa;GACb,aAAa,EAAE,OAAO,EAAE,UAAU,kBAAkB,CAAC,CAAC,CAAC,OAAO;GAC9D,SAAS,OAAO,EAAE,eAAe;IAC/B,MAAM,OAAO,MAAM,YAAY,QAAQ;IACvC,MAAM,UAAU,MAAM,KAAK,UAAU,wBAAwB;KAC3D,OAAO,MAAM;KACb,YAAY,KAAK;KACjB,WAAW,MAAM;IACnB,CAAC;IACD,OAAO;KAAE,UAAU,UAAU,IAAI;KAAG,YAAY;KAAO,eAAe;IAAQ;GAChF;EACF,CAAC;CACH;AACF"}
|
|
@@ -49,6 +49,10 @@ export declare function legacyGithubWorkItemBranch(branch: string): string | und
|
|
|
49
49
|
export declare function pullRequestNumberFromBranch(branch: string): number | undefined;
|
|
50
50
|
/** The GitLab MR IID encoded in Factory's collision-resistant review branch. */
|
|
51
51
|
export declare function mergeRequestNumberFromBranch(branch: string): number | undefined;
|
|
52
|
+
export declare const USER_BRANCH_PREFIX = "user/";
|
|
53
|
+
export declare const USER_SESSION_BRANCH_PREFIX = "user/session-";
|
|
54
|
+
export declare const SLACK_SESSION_BRANCH_PREFIX = "slack/";
|
|
55
|
+
export declare function isPersonSessionBranch(branch: string): boolean;
|
|
52
56
|
/** Whether a provider-reported branch name is safe to show an agent or pass to git. */
|
|
53
57
|
export declare function isSafeBranchName(value: string): boolean;
|
|
54
58
|
//# sourceMappingURL=work-item-branch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-branch.d.ts","sourceRoot":"","sources":["../src/work-item-branch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAEnF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAC5B,cAAc,GACd,WAAW,GACX,cAAc,GACd,WAAW,GACX,cAAc,GACd,YAAY,GACZ,sBAAsB,GACtB,yBAAyB,GACzB,qBAAqB,GACrB,gBAAgB,GAChB,cAAc,GACd,QAAQ,CAAC;AAEb,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,GAAG,oBAAoB,CAepH;AAOD,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG,MAAM,GAAG,SAAS,CAOzG;AAED,yHAAyH;AACzH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACzE,MAAM,CAKR;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE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CAAC,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG,MAAM,GAAG,SAAS,CAOzG;AAED,yHAAyH;AACzH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACzE,MAAM,CAKR;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CA+BhE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAM9G;AAED,+FAA+F;AAC/F,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI9E;AAED,gFAAgF;AAChF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI/E;AAED,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAC1C,eAAO,MAAM,0BAA0B,kBAAkC,CAAC;AAE1E,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAEpD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUvD"}
|
package/dist/work-item-branch.js
CHANGED
|
@@ -103,10 +103,16 @@ function mergeRequestNumberFromBranch(branch) {
|
|
|
103
103
|
const number = match ? Number(match[1]) : void 0;
|
|
104
104
|
return number !== void 0 && Number.isSafeInteger(number) ? number : void 0;
|
|
105
105
|
}
|
|
106
|
+
const USER_BRANCH_PREFIX = "user/";
|
|
107
|
+
const USER_SESSION_BRANCH_PREFIX = `${USER_BRANCH_PREFIX}session-`;
|
|
108
|
+
const SLACK_SESSION_BRANCH_PREFIX = "slack/";
|
|
109
|
+
function isPersonSessionBranch(branch) {
|
|
110
|
+
return branch.startsWith("user/") || branch.startsWith("slack/");
|
|
111
|
+
}
|
|
106
112
|
/** Whether a provider-reported branch name is safe to show an agent or pass to git. */
|
|
107
113
|
function isSafeBranchName(value) {
|
|
108
114
|
return /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) && !value.includes("..") && !value.includes("//") && !value.includes("@{") && !value.endsWith(".") && !value.endsWith("/") && !value.endsWith(".lock");
|
|
109
115
|
}
|
|
110
|
-
export { isSafeBranchName, legacyGithubWorkItemBranch, mergeRequestNumberFromBranch, pullRequestBranch, pullRequestNumberFromBranch, workItemBranch, workItemBranchSource, workItemNumber, workItemThreadTitle };
|
|
116
|
+
export { SLACK_SESSION_BRANCH_PREFIX, USER_BRANCH_PREFIX, USER_SESSION_BRANCH_PREFIX, isPersonSessionBranch, isSafeBranchName, legacyGithubWorkItemBranch, mergeRequestNumberFromBranch, pullRequestBranch, pullRequestNumberFromBranch, workItemBranch, workItemBranchSource, workItemNumber, workItemThreadTitle };
|
|
111
117
|
|
|
112
118
|
//# sourceMappingURL=work-item-branch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-branch.js","names":[],"sources":["../src/work-item-branch.ts"],"sourcesContent":["import type { ExternalWorkItemSource } from './storage/domains/work-items/base.js';\n\n/**\n * Where a card came from, in the vocabulary branch naming reads. Server rows\n * map their `externalSource` into this with {@link workItemBranchSource}; the\n * board's own `WorkItem['source']` is already this union.\n */\nexport type WorkItemBranchSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'github-dependabot-alert'\n | 'vanta-vulnerability'\n | 'detail-finding'\n | 'slack-thread'\n | 'manual';\n\nexport interface WorkItemBranchInput {\n id: string;\n source: WorkItemBranchSource;\n metadata?: Record<string, unknown> | null;\n}\n\n/** Map a stored item's provenance onto the source vocabulary branch naming reads. */\nexport function workItemBranchSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource {\n if (!externalSource) return 'manual';\n if (externalSource.integrationId === 'linear') return 'linear-issue';\n if (externalSource.integrationId === 'gitlab') {\n return externalSource.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n }\n if (externalSource.integrationId === 'jira') return 'jira-issue';\n if (externalSource.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io carry provider identities; anything\n // else (a Slack thread, say) is a plain work item rather than a mislabeled GitHub issue.\n if (externalSource.integrationId === 'vanta') return 'vanta-vulnerability';\n if (externalSource.integrationId === 'detail') return 'detail-finding';\n if (externalSource.integrationId !== 'github') return 'manual';\n if (externalSource.type === 'dependabot-alert') return 'github-dependabot-alert';\n return externalSource.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\nfunction branchNumber(metadata: Record<string, unknown>, key: string): number | undefined {\n const value = metadata[key] ?? metadata.number;\n return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** The provider number a GitHub card carries — the `#12` its runs and thread titles name it by. */\nexport function workItemNumber(item: Pick<WorkItemBranchInput, 'source' | 'metadata'>): number | undefined {\n const metadata = item.metadata ?? {};\n if (item.source === 'github-issue') return branchNumber(metadata, 'githubIssueNumber');\n if (item.source === 'github-pr') return branchNumber(metadata, 'githubPullRequestNumber');\n if (item.source === 'gitlab-issue') return branchNumber(metadata, 'gitlabIssueIid');\n if (item.source === 'gitlab-pr') return branchNumber(metadata, 'gitlabMergeRequestIid');\n return undefined;\n}\n\n/** How a card names its thread: a Linear title already opens with its identifier, a GitHub card gets its number here. */\nexport function workItemThreadTitle(\n item: Pick<WorkItemBranchInput, 'source' | 'metadata'> & { title: string },\n): string {\n const number = workItemNumber(item);\n if (number === undefined) return item.title;\n const kind = item.source === 'github-pr' ? 'PR' : item.source === 'gitlab-pr' ? 'MR' : 'Issue';\n return `${kind} #${number}: ${item.title}`;\n}\n\n/**\n * The last twelve alphanumerics of a work item id: the per-item suffix that keeps\n * provider numbers from colliding across the repositories of one factory. Issue\n * #13 exists in every repository, and a factory's sessions are unique per\n * user and branch across all of its repositories, so a branch named by the\n * number alone can only be held once per factory.\n */\nfunction itemSuffix(id: string): string {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '')\n .slice(-12);\n}\n\n/**\n * The git branch an item's runs and sessions share, one grammar for both sides\n * of the wire: the dispatcher names autonomous run branches with it and the\n * board opens card sessions on it, so both converge on one checkout per item.\n * Provider numbers are only unique within a repository, so GitHub and GitLab\n * branches carry the item suffix as well. Cards without a provider identity\n * (manual, Slack) and cards whose metadata lost their identifier fall back to\n * the id-derived branch.\n */\nexport function workItemBranch(item: WorkItemBranchInput): string {\n const metadata = item.metadata ?? {};\n const providerNumber = workItemNumber(item);\n if (providerNumber !== undefined && (item.source === 'github-issue' || item.source === 'github-pr')) {\n const suffix = itemSuffix(item.id);\n const kind = item.source === 'github-issue' ? 'issue' : 'pr';\n return suffix ? `factory/${kind}-${providerNumber}-${suffix}` : `factory/${kind}-${providerNumber}`;\n }\n if (\n (item.source === 'linear-issue' || item.source === 'jira-issue' || item.source === 'incidentio-follow-up') &&\n typeof metadata.identifier === 'string'\n ) {\n const identifier = metadata.identifier.trim();\n if (identifier) {\n const provider = item.source === 'linear-issue' ? 'linear' : item.source === 'jira-issue' ? 'jira' : 'incidentio';\n return `factory/${provider}-${identifier.toLowerCase()}`;\n }\n }\n if (item.source === 'gitlab-pr' && providerNumber !== undefined) {\n const uniqueSuffix = itemSuffix(item.id);\n if (uniqueSuffix) return `factory/gitlab-mr-${providerNumber}-${uniqueSuffix}`;\n }\n if (item.source === 'gitlab-issue' && typeof metadata.identifier === 'string') {\n const identifier = metadata.identifier\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-');\n const uniqueSuffix = itemSuffix(item.id);\n if (identifier && uniqueSuffix) return `factory/gitlab-${identifier.slice(0, 60)}-${uniqueSuffix}`;\n }\n return `factory/item-${item.id}`;\n}\n\n/**\n * The branch a card's pull or merge request is reviewed on. A PR's own card gets\n * the same name {@link workItemBranch} gives it; an issue card reviewing a PR\n * attached to it gets a branch apart from its builder's issue branch, so the\n * reviewer and the builder never share a checkout.\n */\nexport function pullRequestBranch(input: { id: string; provider: 'github' | 'gitlab'; number: number }): string {\n const suffix = itemSuffix(input.id);\n if (input.provider === 'gitlab') {\n return suffix ? `factory/gitlab-mr-${input.number}-${suffix}` : `factory/item-${input.id}-mr-${input.number}`;\n }\n return suffix ? `factory/pr-${input.number}-${suffix}` : `factory/pr-${input.number}`;\n}\n\n/** The pre-suffix GitHub branch, for reusing sessions opened before card names were unique. */\nexport function legacyGithubWorkItemBranch(branch: string): string | undefined {\n const match = /^(factory\\/(?:issue|pr)-[1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n return match?.[1];\n}\n\n/**\n * The pull request a `factory/pr-<number>-<item suffix>` branch was named after, the\n * inverse of {@link workItemBranch}. Branches from before the suffix (`factory/pr-<number>`)\n * still parse so existing checkouts can resolve their PR.\n */\nexport function pullRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/pr-([1-9]\\d*)(?:-[a-z0-9]{1,12})?$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\n/** The GitLab MR IID encoded in Factory's collision-resistant review branch. */\nexport function mergeRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/gitlab-mr-([1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\n/** Whether a provider-reported branch name is safe to show an agent or pass to git. */\nexport function isSafeBranchName(value: string): boolean {\n return (\n /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) &&\n !value.includes('..') &&\n !value.includes('//') &&\n !value.includes('@{') &&\n !value.endsWith('.') &&\n !value.endsWith('/') &&\n !value.endsWith('.lock')\n );\n}\n"],"mappings":";;AA4BA,SAAgB,qBAAqB,gBAAiF;CACpH,IAAI,CAAC,gBAAgB,OAAO;CAC5B,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UACnC,OAAO,eAAe,SAAS,iBAAiB,cAAc;CAEhE,IAAI,eAAe,kBAAkB,QAAQ,OAAO;CACpD,IAAI,eAAe,kBAAkB,cAAc,OAAO;CAG1D,IAAI,eAAe,kBAAkB,SAAS,OAAO;CACrD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,SAAS,oBAAoB,OAAO;CACvD,OAAO,eAAe,SAAS,iBAAiB,cAAc;AAChE;AAEA,SAAS,aAAa,UAAmC,KAAiC;CACxF,MAAM,QAAQ,SAAS,QAAQ,SAAS;CACxC,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,KAAK,QAAQ,IAAI,QAAQ,KAAA;AACrF;;AAGA,SAAgB,eAAe,MAA4E;CACzG,MAAM,WAAW,KAAK,YAAY,CAAC;CACnC,IAAI,KAAK,WAAW,gBAAgB,OAAO,aAAa,UAAU,mBAAmB;CACrF,IAAI,KAAK,WAAW,aAAa,OAAO,aAAa,UAAU,yBAAyB;CACxF,IAAI,KAAK,WAAW,gBAAgB,OAAO,aAAa,UAAU,gBAAgB;CAClF,IAAI,KAAK,WAAW,aAAa,OAAO,aAAa,UAAU,uBAAuB;AAExF;;AAGA,SAAgB,oBACd,MACQ;CACR,MAAM,SAAS,eAAe,IAAI;CAClC,IAAI,WAAW,KAAA,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KAAK;AAC9B;;;;;;;AAQA,SAAgB,kBAAkB,OAA8E;CAC9G,MAAM,SAAS,WAAW,MAAM,EAAE;CAClC,IAAI,MAAM,aAAa,UACrB,OAAO,SAAS,qBAAqB,MAAM,OAAO,GAAG,WAAW,gBAAgB,MAAM,GAAG,MAAM,MAAM;CAEvG,OAAO,SAAS,cAAc,MAAM,OAAO,GAAG,WAAW,cAAc,MAAM;AAC/E;;AAGA,SAAgB,2BAA2B,QAAoC;CAE7E,OADc,oDAAoD,KAAK,MAC5D,CAAC,GAAG;AACjB;;;;;;AAOA,SAAgB,4BAA4B,QAAoC;CAC9E,MAAM,QAAQ,+CAA+C,KAAK,MAAM;CACxE,MAAM,SAAS,QAAQ,OAAO,MAAM,EAAE,IAAI,KAAA;CAC1C,OAAO,WAAW,KAAA,KAAa,OAAO,cAAc,MAAM,IAAI,SAAS,KAAA;AACzE;;AAGA,SAAgB,6BAA6B,QAAoC;CAC/E,MAAM,QAAQ,iDAAiD,KAAK,MAAM;CAC1E,MAAM,SAAS,QAAQ,OAAO,MAAM,EAAE,IAAI,KAAA;CAC1C,OAAO,WAAW,KAAA,KAAa,OAAO,cAAc,MAAM,IAAI,SAAS,KAAA;AACzE;;AAGA,SAAgB,iBAAiB,OAAwB;CACvD,OACE,kCAAkC,KAAK,KAAK,KAC5C,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,OAAO;AAE3B"}
|
|
1
|
+
{"version":3,"file":"work-item-branch.js","names":[],"sources":["../src/work-item-branch.ts"],"sourcesContent":["import type { ExternalWorkItemSource } from './storage/domains/work-items/base.js';\n\n/**\n * Where a card came from, in the vocabulary branch naming reads. Server rows\n * map their `externalSource` into this with {@link workItemBranchSource}; the\n * board's own `WorkItem['source']` is already this union.\n */\nexport type WorkItemBranchSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'github-dependabot-alert'\n | 'vanta-vulnerability'\n | 'detail-finding'\n | 'slack-thread'\n | 'manual';\n\nexport interface WorkItemBranchInput {\n id: string;\n source: WorkItemBranchSource;\n metadata?: Record<string, unknown> | null;\n}\n\n/** Map a stored item's provenance onto the source vocabulary branch naming reads. */\nexport function workItemBranchSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource {\n if (!externalSource) return 'manual';\n if (externalSource.integrationId === 'linear') return 'linear-issue';\n if (externalSource.integrationId === 'gitlab') {\n return externalSource.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n }\n if (externalSource.integrationId === 'jira') return 'jira-issue';\n if (externalSource.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io carry provider identities; anything\n // else (a Slack thread, say) is a plain work item rather than a mislabeled GitHub issue.\n if (externalSource.integrationId === 'vanta') return 'vanta-vulnerability';\n if (externalSource.integrationId === 'detail') return 'detail-finding';\n if (externalSource.integrationId !== 'github') return 'manual';\n if (externalSource.type === 'dependabot-alert') return 'github-dependabot-alert';\n return externalSource.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\nfunction branchNumber(metadata: Record<string, unknown>, key: string): number | undefined {\n const value = metadata[key] ?? metadata.number;\n return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** The provider number a GitHub card carries — the `#12` its runs and thread titles name it by. */\nexport function workItemNumber(item: Pick<WorkItemBranchInput, 'source' | 'metadata'>): number | undefined {\n const metadata = item.metadata ?? {};\n if (item.source === 'github-issue') return branchNumber(metadata, 'githubIssueNumber');\n if (item.source === 'github-pr') return branchNumber(metadata, 'githubPullRequestNumber');\n if (item.source === 'gitlab-issue') return branchNumber(metadata, 'gitlabIssueIid');\n if (item.source === 'gitlab-pr') return branchNumber(metadata, 'gitlabMergeRequestIid');\n return undefined;\n}\n\n/** How a card names its thread: a Linear title already opens with its identifier, a GitHub card gets its number here. */\nexport function workItemThreadTitle(\n item: Pick<WorkItemBranchInput, 'source' | 'metadata'> & { title: string },\n): string {\n const number = workItemNumber(item);\n if (number === undefined) return item.title;\n const kind = item.source === 'github-pr' ? 'PR' : item.source === 'gitlab-pr' ? 'MR' : 'Issue';\n return `${kind} #${number}: ${item.title}`;\n}\n\n/**\n * The last twelve alphanumerics of a work item id: the per-item suffix that keeps\n * provider numbers from colliding across the repositories of one factory. Issue\n * #13 exists in every repository, and a factory's sessions are unique per\n * user and branch across all of its repositories, so a branch named by the\n * number alone can only be held once per factory.\n */\nfunction itemSuffix(id: string): string {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '')\n .slice(-12);\n}\n\n/**\n * The git branch an item's runs and sessions share, one grammar for both sides\n * of the wire: the dispatcher names autonomous run branches with it and the\n * board opens card sessions on it, so both converge on one checkout per item.\n * Provider numbers are only unique within a repository, so GitHub and GitLab\n * branches carry the item suffix as well. Cards without a provider identity\n * (manual, Slack) and cards whose metadata lost their identifier fall back to\n * the id-derived branch.\n */\nexport function workItemBranch(item: WorkItemBranchInput): string {\n const metadata = item.metadata ?? {};\n const providerNumber = workItemNumber(item);\n if (providerNumber !== undefined && (item.source === 'github-issue' || item.source === 'github-pr')) {\n const suffix = itemSuffix(item.id);\n const kind = item.source === 'github-issue' ? 'issue' : 'pr';\n return suffix ? `factory/${kind}-${providerNumber}-${suffix}` : `factory/${kind}-${providerNumber}`;\n }\n if (\n (item.source === 'linear-issue' || item.source === 'jira-issue' || item.source === 'incidentio-follow-up') &&\n typeof metadata.identifier === 'string'\n ) {\n const identifier = metadata.identifier.trim();\n if (identifier) {\n const provider = item.source === 'linear-issue' ? 'linear' : item.source === 'jira-issue' ? 'jira' : 'incidentio';\n return `factory/${provider}-${identifier.toLowerCase()}`;\n }\n }\n if (item.source === 'gitlab-pr' && providerNumber !== undefined) {\n const uniqueSuffix = itemSuffix(item.id);\n if (uniqueSuffix) return `factory/gitlab-mr-${providerNumber}-${uniqueSuffix}`;\n }\n if (item.source === 'gitlab-issue' && typeof metadata.identifier === 'string') {\n const identifier = metadata.identifier\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-');\n const uniqueSuffix = itemSuffix(item.id);\n if (identifier && uniqueSuffix) return `factory/gitlab-${identifier.slice(0, 60)}-${uniqueSuffix}`;\n }\n return `factory/item-${item.id}`;\n}\n\n/**\n * The branch a card's pull or merge request is reviewed on. A PR's own card gets\n * the same name {@link workItemBranch} gives it; an issue card reviewing a PR\n * attached to it gets a branch apart from its builder's issue branch, so the\n * reviewer and the builder never share a checkout.\n */\nexport function pullRequestBranch(input: { id: string; provider: 'github' | 'gitlab'; number: number }): string {\n const suffix = itemSuffix(input.id);\n if (input.provider === 'gitlab') {\n return suffix ? `factory/gitlab-mr-${input.number}-${suffix}` : `factory/item-${input.id}-mr-${input.number}`;\n }\n return suffix ? `factory/pr-${input.number}-${suffix}` : `factory/pr-${input.number}`;\n}\n\n/** The pre-suffix GitHub branch, for reusing sessions opened before card names were unique. */\nexport function legacyGithubWorkItemBranch(branch: string): string | undefined {\n const match = /^(factory\\/(?:issue|pr)-[1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n return match?.[1];\n}\n\n/**\n * The pull request a `factory/pr-<number>-<item suffix>` branch was named after, the\n * inverse of {@link workItemBranch}. Branches from before the suffix (`factory/pr-<number>`)\n * still parse so existing checkouts can resolve their PR.\n */\nexport function pullRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/pr-([1-9]\\d*)(?:-[a-z0-9]{1,12})?$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\n/** The GitLab MR IID encoded in Factory's collision-resistant review branch. */\nexport function mergeRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/gitlab-mr-([1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\nexport const USER_BRANCH_PREFIX = 'user/';\nexport const USER_SESSION_BRANCH_PREFIX = `${USER_BRANCH_PREFIX}session-`;\n// Slack thread sessions live on `slack/<thread>` branches (integrations/slack/slack.ts threadBranch).\nexport const SLACK_SESSION_BRANCH_PREFIX = 'slack/';\n\nexport function isPersonSessionBranch(branch: string): boolean {\n return branch.startsWith(USER_BRANCH_PREFIX) || branch.startsWith(SLACK_SESSION_BRANCH_PREFIX);\n}\n\n/** Whether a provider-reported branch name is safe to show an agent or pass to git. */\nexport function isSafeBranchName(value: string): boolean {\n return (\n /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) &&\n !value.includes('..') &&\n !value.includes('//') &&\n !value.includes('@{') &&\n !value.endsWith('.') &&\n !value.endsWith('/') &&\n !value.endsWith('.lock')\n );\n}\n"],"mappings":";;AA4BA,SAAgB,qBAAqB,gBAAiF;CACpH,IAAI,CAAC,gBAAgB,OAAO;CAC5B,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UACnC,OAAO,eAAe,SAAS,iBAAiB,cAAc;CAEhE,IAAI,eAAe,kBAAkB,QAAQ,OAAO;CACpD,IAAI,eAAe,kBAAkB,cAAc,OAAO;CAG1D,IAAI,eAAe,kBAAkB,SAAS,OAAO;CACrD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,SAAS,oBAAoB,OAAO;CACvD,OAAO,eAAe,SAAS,iBAAiB,cAAc;AAChE;AAEA,SAAS,aAAa,UAAmC,KAAiC;CACxF,MAAM,QAAQ,SAAS,QAAQ,SAAS;CACxC,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,KAAK,QAAQ,IAAI,QAAQ,KAAA;AACrF;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AyB;CAC7D,OAAO,OAAO,WAAA,OAA6B,KAAK,OAAO,WAAA,QAAsC;AAC/F;;AAGA,SAAgB,iBAAiB,OAAwB;CACvD,OACE,kCAAkC,KAAK,KAAK,KAC5C,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,OAAO;AAE3B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
interface SessionRef {
|
|
2
|
+
readonly sessionId: string;
|
|
3
|
+
readonly threadId: string;
|
|
4
|
+
}
|
|
5
|
+
interface ContextCard<Ref extends SessionRef> {
|
|
6
|
+
readonly sessions: Readonly<Record<string, Ref>>;
|
|
7
|
+
readonly stageHistory: readonly {
|
|
8
|
+
readonly stage: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The card's single conversation. A work item keeps one threadId for its whole
|
|
13
|
+
* lifecycle — every run reuses the worktree's thread — so the card title links
|
|
14
|
+
* to exactly one thread. Items filed while session scoping was broken may
|
|
15
|
+
* still carry divergent role refs; prefer the earliest lifecycle role because
|
|
16
|
+
* JSON object key order is not a stable record of which ref was filed first.
|
|
17
|
+
*/
|
|
18
|
+
export declare function itemThreadSession<Ref extends SessionRef>(sessions: Readonly<Record<string, Ref>>): Ref | undefined;
|
|
19
|
+
export interface ContextPhase {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
readonly context?: string;
|
|
24
|
+
readonly role?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CardContextSession<Ref extends SessionRef = SessionRef> {
|
|
27
|
+
context: string;
|
|
28
|
+
label: string;
|
|
29
|
+
ref: Ref;
|
|
30
|
+
/** The card's current phase runs in this context. */
|
|
31
|
+
current: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** The session context a phase runs in; `role` is its deprecated name. */
|
|
34
|
+
export declare function phaseContext(phase: Pick<ContextPhase, 'context' | 'role'>): string | undefined;
|
|
35
|
+
/** A context named after its one phase, else by its well-known name, else by its key. */
|
|
36
|
+
export declare function contextLabel(context: string, phases: readonly ContextPhase[] | undefined): string;
|
|
37
|
+
/**
|
|
38
|
+
* Every session a card holds, one per context: the context its current phase
|
|
39
|
+
* runs in first, then the contexts of its most recently visited phases, then
|
|
40
|
+
* the rest. A session filed under two keys is listed once, under the first.
|
|
41
|
+
*/
|
|
42
|
+
export declare function cardContextSessions<Ref extends SessionRef>(item: ContextCard<Ref>, phases: readonly ContextPhase[] | undefined, columnStage: string): CardContextSession<Ref>[];
|
|
43
|
+
/**
|
|
44
|
+
* The session a card opens: its current phase's context, else the context of
|
|
45
|
+
* the phase it last visited. Without a board catalog, or when no visited phase
|
|
46
|
+
* holds a session, it keeps the lifecycle order of `itemThreadSession`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cardThreadSession<Ref extends SessionRef>(item: ContextCard<Ref>, phases: readonly ContextPhase[] | undefined, columnStage: string): Ref | undefined;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=card-context-sessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-context-sessions.d.ts","sourceRoot":"","sources":["../../src/work-items/card-context-sessions.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,WAAW,CAAC,GAAG,SAAS,UAAU;IAC1C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,YAAY,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,C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ACtB,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,EAC3C,WAAW,EAAE,MAAM,GAClB,GAAG,GAAG,SAAS,CAGjB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/work-items/card-context-sessions.ts
|
|
2
|
+
/**
|
|
3
|
+
* The card's single conversation. A work item keeps one threadId for its whole
|
|
4
|
+
* lifecycle — every run reuses the worktree's thread — so the card title links
|
|
5
|
+
* to exactly one thread. Items filed while session scoping was broken may
|
|
6
|
+
* still carry divergent role refs; prefer the earliest lifecycle role because
|
|
7
|
+
* JSON object key order is not a stable record of which ref was filed first.
|
|
8
|
+
*/
|
|
9
|
+
function itemThreadSession(sessions) {
|
|
10
|
+
return sessions.triage ?? sessions.plan ?? sessions.work ?? sessions.review ?? sessions.chat ?? Object.values(sessions)[0];
|
|
11
|
+
}
|
|
12
|
+
const CONTEXT_LABELS = {
|
|
13
|
+
triage: "Triage",
|
|
14
|
+
work: "Work",
|
|
15
|
+
review: "Review",
|
|
16
|
+
plan: "Planning",
|
|
17
|
+
chat: "Chat"
|
|
18
|
+
};
|
|
19
|
+
/** The session context a phase runs in; `role` is its deprecated name. */
|
|
20
|
+
function phaseContext(phase) {
|
|
21
|
+
return phase.context ?? phase.role;
|
|
22
|
+
}
|
|
23
|
+
/** A context named after its one phase, else by its well-known name, else by its key. */
|
|
24
|
+
function contextLabel(context, phases) {
|
|
25
|
+
const [only, ...others] = phases?.filter((phase) => phaseContext(phase) === context) ?? [];
|
|
26
|
+
if (only && others.length === 0) return only.name ?? only.title;
|
|
27
|
+
return CONTEXT_LABELS[context] ?? context.charAt(0).toUpperCase() + context.slice(1);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The session a card holds in a context. Cards planned before Planning moved
|
|
31
|
+
* into `work` hold their planner under the old `plan` key, which stands in for
|
|
32
|
+
* `work` until the card gets a `work` session, unless a phase runs in `plan`.
|
|
33
|
+
*/
|
|
34
|
+
function contextSession(item, phases, context) {
|
|
35
|
+
const legacyPlanner = context === "work" && !phases.some((phase) => phaseContext(phase) === "plan");
|
|
36
|
+
return item.sessions[context] ?? (legacyPlanner ? item.sessions.plan : void 0);
|
|
37
|
+
}
|
|
38
|
+
/** Contexts holding a session, by the card's current phase first, then its most recently visited phases. */
|
|
39
|
+
function visitedContexts(item, phases, columnStage) {
|
|
40
|
+
const contexts = [];
|
|
41
|
+
for (const stage of [columnStage, ...item.stageHistory.map((entry) => entry.stage).reverse()]) {
|
|
42
|
+
const phase = phases.find((candidate) => candidate.id === stage);
|
|
43
|
+
const context = phase && phaseContext(phase);
|
|
44
|
+
if (context !== void 0 && contextSession(item, phases, context) && !contexts.includes(context)) contexts.push(context);
|
|
45
|
+
}
|
|
46
|
+
return contexts;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Every session a card holds, one per context: the context its current phase
|
|
50
|
+
* runs in first, then the contexts of its most recently visited phases, then
|
|
51
|
+
* the rest. A session filed under two keys is listed once, under the first.
|
|
52
|
+
*/
|
|
53
|
+
function cardContextSessions(item, phases, columnStage) {
|
|
54
|
+
const currentPhase = phases?.find((phase) => phase.id === columnStage);
|
|
55
|
+
const currentContext = currentPhase && phaseContext(currentPhase);
|
|
56
|
+
const visited = phases ? visitedContexts(item, phases, columnStage) : [];
|
|
57
|
+
const order = [.../* @__PURE__ */ new Set([...visited, ...Object.keys(item.sessions)])];
|
|
58
|
+
const seen = /* @__PURE__ */ new Set();
|
|
59
|
+
return order.flatMap((context) => {
|
|
60
|
+
const ref = (phases && contextSession(item, phases, context)) ?? item.sessions[context];
|
|
61
|
+
if (!ref) return [];
|
|
62
|
+
const key = `${ref.sessionId}:${ref.threadId}`;
|
|
63
|
+
if (seen.has(key)) return [];
|
|
64
|
+
seen.add(key);
|
|
65
|
+
return [{
|
|
66
|
+
context,
|
|
67
|
+
label: contextLabel(context, phases),
|
|
68
|
+
ref,
|
|
69
|
+
current: context === currentContext
|
|
70
|
+
}];
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The session a card opens: its current phase's context, else the context of
|
|
75
|
+
* the phase it last visited. Without a board catalog, or when no visited phase
|
|
76
|
+
* holds a session, it keeps the lifecycle order of `itemThreadSession`.
|
|
77
|
+
*/
|
|
78
|
+
function cardThreadSession(item, phases, columnStage) {
|
|
79
|
+
const context = phases ? visitedContexts(item, phases, columnStage)[0] : void 0;
|
|
80
|
+
return phases && context !== void 0 ? contextSession(item, phases, context) : itemThreadSession(item.sessions);
|
|
81
|
+
}
|
|
82
|
+
export { cardContextSessions, cardThreadSession, contextLabel, itemThreadSession, phaseContext };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=card-context-sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-context-sessions.js","names":[],"sources":["../../src/work-items/card-context-sessions.ts"],"sourcesContent":["interface SessionRef {\n readonly sessionId: string;\n readonly threadId: string;\n}\n\ninterface ContextCard<Ref extends SessionRef> {\n readonly sessions: Readonly<Record<string, Ref>>;\n readonly stageHistory: readonly { readonly stage: string }[];\n}\n\n/**\n * The card's single conversation. A work item keeps one threadId for its whole\n * lifecycle — every run reuses the worktree's thread — so the card title links\n * to exactly one thread. Items filed while session scoping was broken may\n * still carry divergent role refs; prefer the earliest lifecycle role because\n * JSON object key order is not a stable record of which ref was filed first.\n */\nexport function itemThreadSession<Ref extends SessionRef>(sessions: Readonly<Record<string, Ref>>): Ref | undefined {\n return (\n sessions.triage ?? sessions.plan ?? sessions.work ?? sessions.review ?? sessions.chat ?? Object.values(sessions)[0]\n );\n}\n\nexport interface ContextPhase {\n readonly id: string;\n readonly title: string;\n readonly name?: string;\n readonly context?: string;\n readonly role?: string;\n}\n\nexport interface CardContextSession<Ref extends SessionRef = SessionRef> {\n context: string;\n label: string;\n ref: Ref;\n /** The card's current phase runs in this context. */\n current: boolean;\n}\n\nconst CONTEXT_LABELS: Record<string, string> = {\n triage: 'Triage',\n work: 'Work',\n review: 'Review',\n plan: 'Planning',\n chat: 'Chat',\n};\n\n/** The session context a phase runs in; `role` is its deprecated name. */\nexport function phaseContext(phase: Pick<ContextPhase, 'context' | 'role'>): string | undefined {\n return phase.context ?? phase.role;\n}\n\n/** A context named after its one phase, else by its well-known name, else by its key. */\nexport function contextLabel(context: string, phases: readonly ContextPhase[] | undefined): string {\n const [only, ...others] = phases?.filter(phase => phaseContext(phase) === context) ?? [];\n if (only && others.length === 0) return only.name ?? only.title;\n return CONTEXT_LABELS[context] ?? context.charAt(0).toUpperCase() + context.slice(1);\n}\n\n/**\n * The session a card holds in a context. Cards planned before Planning moved\n * into `work` hold their planner under the old `plan` key, which stands in for\n * `work` until the card gets a `work` session, unless a phase runs in `plan`.\n */\nfunction contextSession<Ref extends SessionRef>(\n item: Pick<ContextCard<Ref>, 'sessions'>,\n phases: readonly ContextPhase[],\n context: string,\n): Ref | undefined {\n const legacyPlanner = context === 'work' && !phases.some(phase => phaseContext(phase) === 'plan');\n return item.sessions[context] ?? (legacyPlanner ? item.sessions.plan : undefined);\n}\n\n/** Contexts holding a session, by the card's current phase first, then its most recently visited phases. */\nfunction visitedContexts<Ref extends SessionRef>(\n item: ContextCard<Ref>,\n phases: readonly ContextPhase[],\n columnStage: string,\n): string[] {\n const contexts: string[] = [];\n for (const stage of [columnStage, ...item.stageHistory.map(entry => entry.stage).reverse()]) {\n const phase = phases.find(candidate => candidate.id === stage);\n const context = phase && phaseContext(phase);\n if (context !== undefined && contextSession(item, phases, context) && !contexts.includes(context)) {\n contexts.push(context);\n }\n }\n return contexts;\n}\n\n/**\n * Every session a card holds, one per context: the context its current phase\n * runs in first, then the contexts of its most recently visited phases, then\n * the rest. A session filed under two keys is listed once, under the first.\n */\nexport function cardContextSessions<Ref extends SessionRef>(\n item: ContextCard<Ref>,\n phases: readonly ContextPhase[] | undefined,\n columnStage: string,\n): CardContextSession<Ref>[] {\n const currentPhase = phases?.find(phase => phase.id === columnStage);\n const currentContext = currentPhase && phaseContext(currentPhase);\n const visited = phases ? visitedContexts(item, phases, columnStage) : [];\n const order = [...new Set([...visited, ...Object.keys(item.sessions)])];\n const seen = new Set<string>();\n return order.flatMap(context => {\n const ref = (phases && contextSession(item, phases, context)) ?? item.sessions[context];\n if (!ref) return [];\n const key = `${ref.sessionId}:${ref.threadId}`;\n if (seen.has(key)) return [];\n seen.add(key);\n return [{ context, label: contextLabel(context, phases), ref, current: context === currentContext }];\n });\n}\n\n/**\n * The session a card opens: its current phase's context, else the context of\n * the phase it last visited. Without a board catalog, or when no visited phase\n * holds a session, it keeps the lifecycle order of `itemThreadSession`.\n */\nexport function cardThreadSession<Ref extends SessionRef>(\n item: ContextCard<Ref>,\n phases: readonly ContextPhase[] | undefined,\n columnStage: string,\n): Ref | undefined {\n const context = phases ? visitedContexts(item, phases, columnStage)[0] : undefined;\n return phases && context !== undefined ? contextSession(item, phases, context) : itemThreadSession(item.sessions);\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,kBAA0C,UAA0D;CAClH,OACE,SAAS,UAAU,SAAS,QAAQ,SAAS,QAAQ,SAAS,UAAU,SAAS,QAAQ,OAAO,OAAO,QAAQ,CAAC,CAAC;AAErH;AAkBA,MAAM,iBAAyC;CAC7C,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;CACN,MAAM;AACR;;AAGA,SAAgB,aAAa,OAAmE;CAC9F,OAAO,MAAM,WAAW,MAAM;AAChC;;AAGA,SAAgB,aAAa,SAAiB,QAAqD;CACjG,MAAM,CAAC,MAAM,GAAG,UAAU,QAAQ,QAAO,UAAS,aAAa,KAAK,MAAM,OAAO,KAAK,CAAC;CACvF,IAAI,QAAQ,OAAO,WAAW,GAAG,OAAO,KAAK,QAAQ,KAAK;CAC1D,OAAO,eAAe,YAAY,QAAQ,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,QAAQ,MAAM,CAAC;AACrF;;;;;;AAOA,SAAS,eACP,MACA,QACA,SACiB;CACjB,MAAM,gBAAgB,YAAY,UAAU,C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AAOA,SAAgB,kBACd,MACA,QACA,aACiB;CACjB,MAAM,UAAU,SAAS,gBAAgB,MAAM,QAAQ,WAAW,CAAC,CAAC,KAAK,KAAA;CACzE,OAAO,UAAU,YAAY,KAAA,IAAY,eAAe,MAAM,QAAQ,OAAO,IAAI,kBAAkB,KAAK,QAAQ;AAClH"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { WorkItemSourceRow } from '../storage/domains/work-items/work-item-schema.js';
|
|
2
|
+
export interface SourcedItem {
|
|
3
|
+
readonly workItem?: {
|
|
4
|
+
readonly sources?: readonly WorkItemSourceRow[];
|
|
5
|
+
} | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A card whose own primary source is a pull or merge request: an outside contributor's
|
|
9
|
+
* PR filed on its own card, or a PR card filed before PRs attached to their issue's card.
|
|
10
|
+
* An issue card with an attached PR is not one; see `hasPullRequest`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPullRequestCard(item: {
|
|
13
|
+
readonly source: string;
|
|
14
|
+
}): boolean;
|
|
15
|
+
/** Every pull or merge request source on a card, oldest first. */
|
|
16
|
+
export declare function pullRequestSources(item: SourcedItem): WorkItemSourceRow[];
|
|
17
|
+
/** The provider number (GitHub PR number, GitLab MR IID) a pull request source names. */
|
|
18
|
+
export declare function pullRequestSourceNumber(source: Pick<WorkItemSourceRow, 'metadata'>): number | undefined;
|
|
19
|
+
export declare function isOpenPullRequestSource(source: Pick<WorkItemSourceRow, 'state' | 'metadata'>): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Card metadata listing the attached pull requests whose author had no write access, as
|
|
22
|
+
* `<provider>:<externalId>`. Before any author's pull request could join a card only trusted
|
|
23
|
+
* ones did, so a source missing from the list is trusted.
|
|
24
|
+
*/
|
|
25
|
+
export declare const UNTRUSTED_PULL_REQUESTS_KEY = "untrustedPullRequests";
|
|
26
|
+
/** The key {@link UNTRUSTED_PULL_REQUESTS_KEY} lists a source under. */
|
|
27
|
+
export declare function pullRequestTrustKey(source: Pick<WorkItemSourceRow, 'provider' | 'externalId'>): string;
|
|
28
|
+
/** Whether a pull request attached to the card was opened by someone with write access (or by Factory). */
|
|
29
|
+
export declare function trustedPullRequestSource(item: {
|
|
30
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
31
|
+
}, source: Pick<WorkItemSourceRow, 'provider' | 'externalId'>): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The card's working pull request, the one its review passes and status checks follow: the one
|
|
34
|
+
* `openPullRequestNumber` names (its session's own, or the one a person picked), unless it closed
|
|
35
|
+
* without merging; else the first trusted open one linked, else the first trusted merged one. An
|
|
36
|
+
* outsider's pull request is never picked on its own. `except` leaves one pull request out.
|
|
37
|
+
*/
|
|
38
|
+
export declare function workingPullRequest(item: SourcedItem & {
|
|
39
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
40
|
+
}, except?: number): WorkItemSourceRow | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The pull request `openPullRequestNumber` names, unless it is one linked to the card that closed
|
|
43
|
+
* without merging: the card then works on its {@link workingPullRequest} instead. A pointer to a
|
|
44
|
+
* pull request the card has no source for (its session opened it) stands.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pointedPullRequest(item: SourcedItem & {
|
|
47
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
48
|
+
}): number | undefined;
|
|
49
|
+
/** The pull request a PR review pass on this card reviews: its {@link workingPullRequest}. */
|
|
50
|
+
export declare function reviewedPullRequest(item: SourcedItem & {
|
|
51
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
52
|
+
}): WorkItemSourceRow | undefined;
|
|
53
|
+
export declare const PULL_REQUEST_STATUSES: readonly ['draft', 'open', 'closed', 'merged'];
|
|
54
|
+
export type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];
|
|
55
|
+
export interface CardChangeRequest {
|
|
56
|
+
url?: string;
|
|
57
|
+
provider: 'github' | 'gitlab';
|
|
58
|
+
number?: number;
|
|
59
|
+
/** Undefined while the code host has reported no state. */
|
|
60
|
+
status?: PullRequestStatus;
|
|
61
|
+
draft: boolean;
|
|
62
|
+
/** Epoch milliseconds of the code host's last report. */
|
|
63
|
+
syncedAt?: number;
|
|
64
|
+
}
|
|
65
|
+
interface ChangeRequestCard {
|
|
66
|
+
readonly source: string;
|
|
67
|
+
readonly url?: string | null;
|
|
68
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
69
|
+
readonly workItem?: {
|
|
70
|
+
readonly provider?: string;
|
|
71
|
+
readonly state?: string | null;
|
|
72
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
73
|
+
readonly sources?: readonly WorkItemSourceRow[];
|
|
74
|
+
} | null;
|
|
75
|
+
}
|
|
76
|
+
export declare function isSettledChangeRequest(status: PullRequestStatus | undefined): boolean;
|
|
77
|
+
export declare function changeRequestNumber(source: string, metadata: Record<string, unknown>): number | undefined;
|
|
78
|
+
/** Every pull or merge request a card carries, oldest first. */
|
|
79
|
+
export declare function cardChangeRequests(card: ChangeRequestCard): CardChangeRequest[];
|
|
80
|
+
/**
|
|
81
|
+
* The card's own pull request, else the attached one to show on it: the one `openPullRequestNumber`
|
|
82
|
+
* names, else the newest open one, else the newest one. Unlike {@link reviewedPullRequest} it shows
|
|
83
|
+
* a closed or an outsider's pull request, since showing one starts no work on it.
|
|
84
|
+
*/
|
|
85
|
+
export declare function cardChangeRequest(card: ChangeRequestCard): CardChangeRequest | undefined;
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=change-requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-requests.d.ts","sourceRoot":"","sources":["../../src/work-items/change-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAE3F,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,iBA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nD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;KACjD,GAAG,IAAI,CAAC;CACV;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,GAAG,OAAO,CAErF;AAyBD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS,CAQzG;AAeD,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAI/E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,GAAG,SAAS,CASxF"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/work-items/change-requests.ts
|
|
2
|
+
/**
|
|
3
|
+
* A card whose own primary source is a pull or merge request: an outside contributor's
|
|
4
|
+
* PR filed on its own card, or a PR card filed before PRs attached to their issue's card.
|
|
5
|
+
* An issue card with an attached PR is not one; see `hasPullRequest`.
|
|
6
|
+
*/
|
|
7
|
+
function isPullRequestCard(item) {
|
|
8
|
+
return item.source === "github-pr" || item.source === "gitlab-pr";
|
|
9
|
+
}
|
|
10
|
+
/** Every pull or merge request source on a card, oldest first. */
|
|
11
|
+
function pullRequestSources(item) {
|
|
12
|
+
return (item.workItem?.sources ?? []).filter((source) => source.sourceType === "pull-request");
|
|
13
|
+
}
|
|
14
|
+
/** The provider number (GitHub PR number, GitLab MR IID) a pull request source names. */
|
|
15
|
+
function pullRequestSourceNumber(source) {
|
|
16
|
+
const metadata = source.metadata ?? {};
|
|
17
|
+
const value = metadata.githubPullRequestNumber ?? metadata.gitlabMergeRequestIid ?? metadata.number;
|
|
18
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
19
|
+
}
|
|
20
|
+
function isOpenPullRequestSource(source) {
|
|
21
|
+
return !isSettledChangeRequest(reportedStatus(source.state, source.metadata ?? {}));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Card metadata listing the attached pull requests whose author had no write access, as
|
|
25
|
+
* `<provider>:<externalId>`. Before any author's pull request could join a card only trusted
|
|
26
|
+
* ones did, so a source missing from the list is trusted.
|
|
27
|
+
*/
|
|
28
|
+
const UNTRUSTED_PULL_REQUESTS_KEY = "untrustedPullRequests";
|
|
29
|
+
/** The key {@link UNTRUSTED_PULL_REQUESTS_KEY} lists a source under. */
|
|
30
|
+
function pullRequestTrustKey(source) {
|
|
31
|
+
return `${source.provider}:${source.externalId}`;
|
|
32
|
+
}
|
|
33
|
+
/** Whether a pull request attached to the card was opened by someone with write access (or by Factory). */
|
|
34
|
+
function trustedPullRequestSource(item, source) {
|
|
35
|
+
const untrusted = item.metadata?.[UNTRUSTED_PULL_REQUESTS_KEY];
|
|
36
|
+
return !(Array.isArray(untrusted) && untrusted.includes(pullRequestTrustKey(source)));
|
|
37
|
+
}
|
|
38
|
+
function closedUnmerged(source) {
|
|
39
|
+
return !isOpenPullRequestSource(source) && (source.state ?? source.metadata?.state) !== "merged" && source.metadata?.merged !== true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The card's working pull request, the one its review passes and status checks follow: the one
|
|
43
|
+
* `openPullRequestNumber` names (its session's own, or the one a person picked), unless it closed
|
|
44
|
+
* without merging; else the first trusted open one linked, else the first trusted merged one. An
|
|
45
|
+
* outsider's pull request is never picked on its own. `except` leaves one pull request out.
|
|
46
|
+
*/
|
|
47
|
+
function workingPullRequest(item, except) {
|
|
48
|
+
const sources = pullRequestSources(item).filter((source) => !closedUnmerged(source) && (except === void 0 || pullRequestSourceNumber(source) !== except));
|
|
49
|
+
const pointer = item.metadata?.openPullRequestNumber;
|
|
50
|
+
return (typeof pointer === "number" ? sources.find((source) => pullRequestSourceNumber(source) === pointer) : void 0) ?? sources.find((source) => isOpenPullRequestSource(source) && trustedPullRequestSource(item, source)) ?? sources.find((source) => trustedPullRequestSource(item, source));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The pull request `openPullRequestNumber` names, unless it is one linked to the card that closed
|
|
54
|
+
* without merging: the card then works on its {@link workingPullRequest} instead. A pointer to a
|
|
55
|
+
* pull request the card has no source for (its session opened it) stands.
|
|
56
|
+
*/
|
|
57
|
+
function pointedPullRequest(item) {
|
|
58
|
+
const pointer = item.metadata?.openPullRequestNumber;
|
|
59
|
+
if (typeof pointer !== "number") return void 0;
|
|
60
|
+
const source = pullRequestSources(item).find((entry) => pullRequestSourceNumber(entry) === pointer);
|
|
61
|
+
return source && closedUnmerged(source) ? void 0 : pointer;
|
|
62
|
+
}
|
|
63
|
+
/** The pull request a PR review pass on this card reviews: its {@link workingPullRequest}. */
|
|
64
|
+
function reviewedPullRequest(item) {
|
|
65
|
+
return workingPullRequest(item);
|
|
66
|
+
}
|
|
67
|
+
const PULL_REQUEST_STATUSES = [
|
|
68
|
+
"draft",
|
|
69
|
+
"open",
|
|
70
|
+
"closed",
|
|
71
|
+
"merged"
|
|
72
|
+
];
|
|
73
|
+
function isSettledChangeRequest(status) {
|
|
74
|
+
return status === "merged" || status === "closed";
|
|
75
|
+
}
|
|
76
|
+
function reportedStatus(state, metadata) {
|
|
77
|
+
const reported = state ?? metadata.state;
|
|
78
|
+
if (reported === "merged" || metadata.merged === true) return "merged";
|
|
79
|
+
if (reported === "closed") return "closed";
|
|
80
|
+
if (reported === "open" || reported === "opened" || reported === "locked") return metadata.draft === true ? "draft" : "open";
|
|
81
|
+
}
|
|
82
|
+
function fromSource(source) {
|
|
83
|
+
const metadata = source.metadata ?? {};
|
|
84
|
+
const syncedAt = source.syncedAt ? new Date(source.syncedAt).getTime() : NaN;
|
|
85
|
+
return {
|
|
86
|
+
url: source.url ?? void 0,
|
|
87
|
+
provider: source.provider === "gitlab" ? "gitlab" : "github",
|
|
88
|
+
number: pullRequestSourceNumber(source),
|
|
89
|
+
status: reportedStatus(source.state, metadata),
|
|
90
|
+
draft: metadata.draft === true,
|
|
91
|
+
syncedAt: Number.isNaN(syncedAt) ? void 0 : syncedAt
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function changeRequestNumber(source, metadata) {
|
|
95
|
+
if (source === "github-pr") {
|
|
96
|
+
const number = metadata.githubPullRequestNumber ?? metadata.number;
|
|
97
|
+
return typeof number === "number" && Number.isInteger(number) && number > 0 ? number : void 0;
|
|
98
|
+
}
|
|
99
|
+
if (source !== "gitlab-pr") return void 0;
|
|
100
|
+
const iid = metadata.gitlabMergeRequestIid;
|
|
101
|
+
return typeof iid === "number" && Number.isSafeInteger(iid) && iid > 0 ? iid : void 0;
|
|
102
|
+
}
|
|
103
|
+
/** A pull request card filed before its sources were recorded: the card's own source is the request. */
|
|
104
|
+
function fromLegacyCard(card) {
|
|
105
|
+
const metadata = (card.workItem && card.workItem.provider !== "factory" ? card.workItem?.metadata : card.metadata) ?? {};
|
|
106
|
+
return {
|
|
107
|
+
url: card.url ?? void 0,
|
|
108
|
+
provider: card.source === "gitlab-pr" ? "gitlab" : "github",
|
|
109
|
+
number: changeRequestNumber(card.source, metadata),
|
|
110
|
+
status: reportedStatus(card.workItem?.state, metadata),
|
|
111
|
+
draft: metadata.draft === true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Every pull or merge request a card carries, oldest first. */
|
|
115
|
+
function cardChangeRequests(card) {
|
|
116
|
+
const sources = pullRequestSources(card);
|
|
117
|
+
if (sources.length > 0) return sources.map(fromSource);
|
|
118
|
+
return isPullRequestCard(card) ? [fromLegacyCard(card)] : [];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The card's own pull request, else the attached one to show on it: the one `openPullRequestNumber`
|
|
122
|
+
* names, else the newest open one, else the newest one. Unlike {@link reviewedPullRequest} it shows
|
|
123
|
+
* a closed or an outsider's pull request, since showing one starts no work on it.
|
|
124
|
+
*/
|
|
125
|
+
function cardChangeRequest(card) {
|
|
126
|
+
if (isPullRequestCard(card)) return cardChangeRequests(card)[0];
|
|
127
|
+
const sources = pullRequestSources(card);
|
|
128
|
+
const pointer = card.metadata?.openPullRequestNumber;
|
|
129
|
+
const attached = (typeof pointer === "number" ? sources.find((source) => pullRequestSourceNumber(source) === pointer) : void 0) ?? sources.findLast(isOpenPullRequestSource) ?? sources.at(-1);
|
|
130
|
+
return attached ? fromSource(attached) : void 0;
|
|
131
|
+
}
|
|
132
|
+
export { PULL_REQUEST_STATUSES, UNTRUSTED_PULL_REQUESTS_KEY, cardChangeRequest, cardChangeRequests, changeRequestNumber, isOpenPullRequestSource, isPullRequestCard, isSettledChangeRequest, pointedPullRequest, pullRequestSourceNumber, pullRequestSources, pullRequestTrustKey, reviewedPullRequest, trustedPullRequestSource, workingPullRequest };
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=change-requests.js.map
|