@mastra/factory 0.27.0-alpha.2 → 0.27.0
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 +94 -47
- package/dist/boards/card-facts.d.ts +4 -2
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +7 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/define-board.d.ts +2 -0
- package/dist/boards/define-board.d.ts.map +1 -1
- package/dist/boards/define-board.js +1 -0
- package/dist/boards/define-board.js.map +1 -1
- package/dist/boards/intake-routing.d.ts +2 -2
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/phase-automation.d.ts +4 -4
- package/dist/boards/phase-automation.d.ts.map +1 -1
- package/dist/boards/phase-automation.js.map +1 -1
- package/dist/boards/pull-request-review.d.ts +0 -7
- package/dist/boards/pull-request-review.d.ts.map +1 -1
- package/dist/boards/pull-request-review.js +15 -14
- package/dist/boards/pull-request-review.js.map +1 -1
- package/dist/boards/relocate.d.ts +4 -4
- package/dist/boards/relocate.d.ts.map +1 -1
- package/dist/boards/relocate.js +1 -1
- package/dist/boards/relocate.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +1 -2
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -8
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/transition-policy.d.ts +7 -0
- package/dist/boards/transition-policy.d.ts.map +1 -1
- package/dist/boards/transition-policy.js.map +1 -1
- package/dist/boards/work.d.ts +6 -0
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +71 -25
- package/dist/boards/work.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +6 -15
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/integrations/github/acceptance-labels.d.ts +2 -2
- package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
- package/dist/integrations/github/acceptance-labels.js +2 -2
- package/dist/integrations/github/acceptance-labels.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +5 -11
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +6 -22
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +6 -4
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/provenance.d.ts +2 -2
- package/dist/integrations/github/provenance.d.ts.map +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +46 -1
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +3 -3
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +43 -39
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +2 -9
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +2 -19
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.js +2 -2
- package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +11 -11
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +2 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +1 -0
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/issue-reconciler.d.ts +7 -7
- package/dist/integrations/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/issue-reconciler.js +11 -14
- package/dist/integrations/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +1 -0
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/issue-reconciler.js +2 -2
- package/dist/integrations/linear/issue-reconciler.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +1 -1
- 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 +2 -1
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/slack/feed-publisher.d.ts +2 -2
- package/dist/integrations/slack/feed-publisher.d.ts.map +1 -1
- package/dist/integrations/slack/feed-publisher.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js +1 -1
- package/dist/routes/attention-activity.js +1 -1
- package/dist/routes/attention-activity.js.map +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +4 -4
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +2 -2
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/contracts.d.ts +33 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +13 -4
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +1 -1
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/projects.js +3 -2
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/surface.js +4 -4
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +9 -3
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.js +1 -1
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/decision-applicability.d.ts +2 -2
- package/dist/rules/decision-applicability.d.ts.map +1 -1
- package/dist/rules/decision-applicability.js +1 -1
- package/dist/rules/decision-applicability.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +2 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +13 -17
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +2 -2
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +4 -2
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.d.ts.map +1 -1
- package/dist/rules/review-source-tool.js +2 -4
- package/dist/rules/review-source-tool.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +5 -2
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +7 -10
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +8 -16
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +19 -21
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +9 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/session/resource-migration.d.ts +3 -3
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +4 -2
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +2 -2
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/skills/catalog.js +1 -1
- package/dist/storage/domains/comments/base.d.ts.map +1 -1
- package/dist/storage/domains/comments/base.js +15 -8
- package/dist/storage/domains/comments/base.js.map +1 -1
- package/dist/storage/domains/comments/domain.d.ts +2 -2
- package/dist/storage/domains/comments/domain.d.ts.map +1 -1
- package/dist/storage/domains/comments/domain.js +1 -1
- package/dist/storage/domains/comments/domain.js.map +1 -1
- package/dist/storage/domains/comments/feed-sync.d.ts +2 -2
- package/dist/storage/domains/comments/feed-sync.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +0 -3
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +0 -3
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +99 -35
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +318 -170
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/board-version.d.ts +2 -2
- package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
- package/dist/storage/domains/work-items/board-version.js +16 -5
- package/dist/storage/domains/work-items/board-version.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +57 -0
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -0
- package/dist/storage/domains/work-items/cards.js +290 -0
- package/dist/storage/domains/work-items/cards.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +2 -2
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +117 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -0
- package/dist/storage/domains/work-items/work-item-schema.js +300 -0
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -0
- package/dist/tools/read-tools.d.ts +4 -4
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +19 -9
- 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.map +1 -1
- package/dist/tools/side-sessions.d.ts +2 -2
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +12 -17
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts +4 -4
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +65 -27
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/providers/base.d.ts +22 -0
- package/dist/work-items/providers/base.d.ts.map +1 -0
- package/dist/work-items/providers/base.js +44 -0
- package/dist/work-items/providers/base.js.map +1 -0
- package/dist/work-items/providers/factory.d.ts +4 -0
- package/dist/work-items/providers/factory.d.ts.map +1 -0
- package/dist/work-items/providers/factory.js +13 -0
- package/dist/work-items/providers/factory.js.map +1 -0
- package/dist/work-items/providers/github.d.ts +3 -0
- package/dist/work-items/providers/github.d.ts.map +1 -0
- package/dist/work-items/providers/github.js +30 -0
- package/dist/work-items/providers/github.js.map +1 -0
- package/dist/work-items/providers/gitlab.d.ts +3 -0
- package/dist/work-items/providers/gitlab.d.ts.map +1 -0
- package/dist/work-items/providers/gitlab.js +35 -0
- package/dist/work-items/providers/gitlab.js.map +1 -0
- package/dist/work-items/providers/incidentio.d.ts +3 -0
- package/dist/work-items/providers/incidentio.d.ts.map +1 -0
- package/dist/work-items/providers/incidentio.js +23 -0
- package/dist/work-items/providers/incidentio.js.map +1 -0
- package/dist/work-items/providers/index.d.ts +8 -0
- package/dist/work-items/providers/index.d.ts.map +1 -0
- package/dist/work-items/providers/index.js +34 -0
- package/dist/work-items/providers/index.js.map +1 -0
- package/dist/work-items/providers/jira.d.ts +3 -0
- package/dist/work-items/providers/jira.d.ts.map +1 -0
- package/dist/work-items/providers/jira.js +16 -0
- package/dist/work-items/providers/jira.js.map +1 -0
- package/dist/work-items/providers/linear.d.ts +3 -0
- package/dist/work-items/providers/linear.d.ts.map +1 -0
- package/dist/work-items/providers/linear.js +24 -0
- package/dist/work-items/providers/linear.js.map +1 -0
- package/dist/work-items/providers/metadata-keys.d.ts +24 -0
- package/dist/work-items/providers/metadata-keys.d.ts.map +1 -0
- package/dist/work-items/providers/metadata-keys.js +84 -0
- package/dist/work-items/providers/metadata-keys.js.map +1 -0
- package/dist/work-items/providers/slack.d.ts +6 -0
- package/dist/work-items/providers/slack.d.ts.map +1 -0
- package/dist/work-items/providers/slack.js +15 -0
- package/dist/work-items/providers/slack.js.map +1 -0
- package/dist/work-items/providers/types.d.ts +23 -0
- package/dist/work-items/providers/types.d.ts.map +1 -0
- package/dist/work-items/providers/types.js +1 -0
- package/dist/work-items/split-migration.d.ts +51 -0
- package/dist/work-items/split-migration.d.ts.map +1 -0
- package/dist/work-items/split-migration.js +293 -0
- package/dist/work-items/split-migration.js.map +1 -0
- package/factory-skills/configure-factory-rules/SKILL.md +12 -16
- package/factory-skills/factory-self-review/SKILL.md +1 -1
- package/factory-skills/factory-triage/SKILL.md +3 -3
- package/package.json +15 -15
- package/dist/boards/work-transition-policy.d.ts +0 -3
- package/dist/boards/work-transition-policy.d.ts.map +0 -1
- package/dist/boards/work-transition-policy.js +0 -78
- package/dist/boards/work-transition-policy.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export type { ChannelAccountLink, ChannelAccountLinkEntry, ChannelAccountLinkKey
|
|
|
12
12
|
export { FactoryProjectsStorage } from './storage/domains/projects/base.js';
|
|
13
13
|
export type { FactoryProject } from './storage/domains/projects/base.js';
|
|
14
14
|
export { WorkItemsStorage } from './storage/domains/work-items/base.js';
|
|
15
|
-
export type { CreateWorkItemInput,
|
|
15
|
+
export type { CreateWorkItemInput, Card, BoardItemRow } from './storage/domains/work-items/base.js';
|
|
16
|
+
export { primarySource } from './storage/domains/work-items/work-item-schema.js';
|
|
17
|
+
export type { WorkItemRow, WorkItemSourceRow, WorkItemProvider, } from './storage/domains/work-items/work-item-schema.js';
|
|
16
18
|
export { createStateSigner } from './state-signing.js';
|
|
17
19
|
export type { StateSigner, StateTenant } from './state-signing.js';
|
|
18
20
|
export { createFactorySecretEncryption, createPlaintextFactorySecretEncryption } from './secret-encryption.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,SAAS,GACV,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,4BAA4B,EAC5B,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EAChB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAClF,YAAY,EACV,UAAU,EACV,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,KAAK,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAG1G,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAClF,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC7G,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,YAAY,E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,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,YAAY,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,YAAY,EAAE,mBAAmB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACjF,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,sCAAsC,EAAE,MAAM,wBAAwB,CAAC;AAC/G,YAAY,EACV,sBAAsB,EACtB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createFactoryRouteAuth } from "./auth.js";
|
|
2
2
|
import { BoardDefinitionError, DEFAULT_PHASE_CONTEXT, FACTORY_AGENT_ID, defineBoard } from "./boards/define-board.js";
|
|
3
|
+
import { primarySource } from "./storage/domains/work-items/work-item-schema.js";
|
|
4
|
+
import { WorkItemsStorage } from "./storage/domains/work-items/base.js";
|
|
3
5
|
import { reviewBoard } from "./boards/review.js";
|
|
4
6
|
import { workBoard } from "./boards/work.js";
|
|
5
7
|
import { createBoardRegistry, defaultBoards } from "./boards/registry.js";
|
|
6
8
|
import "./boards/index.js";
|
|
7
|
-
import { WorkItemsStorage } from "./storage/domains/work-items/base.js";
|
|
8
9
|
import { createFactorySecretEncryption, createPlaintextFactorySecretEncryption } from "./secret-encryption.js";
|
|
9
10
|
import { FactoryProjectsStorage } from "./storage/domains/projects/base.js";
|
|
10
11
|
import { waitForPendingFilesystemCapture } from "./session/filesystem-capture.js";
|
|
@@ -12,4 +13,4 @@ import { LocalFactorySandbox } from "./sandbox/local-factory-sandbox.js";
|
|
|
12
13
|
import { createStateSigner } from "./state-signing.js";
|
|
13
14
|
import { ChannelIdentityStorage } from "./storage/domains/channel-identity/base.js";
|
|
14
15
|
import { MastraFactory } from "./factory.js";
|
|
15
|
-
export { BoardDefinitionError, ChannelIdentityStorage, DEFAULT_PHASE_CONTEXT, FACTORY_AGENT_ID, FactoryProjectsStorage, LocalFactorySandbox, MastraFactory, WorkItemsStorage, createBoardRegistry, createFactoryRouteAuth, createFactorySecretEncryption, createPlaintextFactorySecretEncryption, createStateSigner, defaultBoards, defineBoard, reviewBoard, waitForPendingFilesystemCapture, workBoard };
|
|
16
|
+
export { BoardDefinitionError, ChannelIdentityStorage, DEFAULT_PHASE_CONTEXT, FACTORY_AGENT_ID, FactoryProjectsStorage, LocalFactorySandbox, MastraFactory, WorkItemsStorage, createBoardRegistry, createFactoryRouteAuth, createFactorySecretEncryption, createPlaintextFactorySecretEncryption, createStateSigner, defaultBoards, defineBoard, primarySource, reviewBoard, waitForPendingFilesystemCapture, workBoard };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Card } from '../../storage/domains/work-items/base.js';
|
|
3
3
|
import type { GithubIntegration } from './integration.js';
|
|
4
4
|
export interface ReconcileAcceptanceLabelsInput {
|
|
5
5
|
orgId: string;
|
|
6
6
|
factoryProjectId: string;
|
|
7
|
-
item:
|
|
7
|
+
item: Card;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Reflect a maintainer's acceptance of a triaged GitHub issue back on the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acceptance-labels.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/acceptance-labels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"acceptance-labels.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/acceptance-labels.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,WAAW,8BAA8B;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,IAAI,CAAC;CACZ;AAED;;;;;GAKG;AACH,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,0BAA0B,EACzC,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -9,8 +9,8 @@ import { NEEDS_APPROVAL_LABEL } from "../../rules/types.js";
|
|
|
9
9
|
async function reconcileGithubAcceptanceLabels(github, sourceControl, input) {
|
|
10
10
|
const { item } = input;
|
|
11
11
|
if (item.externalSource?.integrationId !== "github" || item.externalSource.type !== "issue") return;
|
|
12
|
-
const repositoryId = item.metadata?.githubRepositoryId;
|
|
13
|
-
const issueNumber = item.metadata?.githubIssueNumber;
|
|
12
|
+
const repositoryId = item.workItem.metadata?.githubRepositoryId;
|
|
13
|
+
const issueNumber = item.workItem.metadata?.githubIssueNumber;
|
|
14
14
|
if (typeof repositoryId !== "number" || typeof issueNumber !== "number" || issueNumber < 1) return;
|
|
15
15
|
try {
|
|
16
16
|
const target = await resolveRepository(sourceControl, input.orgId, input.factoryProjectId, repositoryId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acceptance-labels.js","names":[],"sources":["../../../src/integrations/github/acceptance-labels.ts"],"sourcesContent":["import { NEEDS_APPROVAL_LABEL } from '../../rules/types.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"acceptance-labels.js","names":[],"sources":["../../../src/integrations/github/acceptance-labels.ts"],"sourcesContent":["import { NEEDS_APPROVAL_LABEL } from '../../rules/types.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { Card } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\n\nexport interface ReconcileAcceptanceLabelsInput {\n orgId: string;\n factoryProjectId: string;\n item: Card;\n}\n\n/**\n * Reflect a maintainer's acceptance of a triaged GitHub issue back on the\n * issue: the triage skill stamps `status: needs approval` and never removes it,\n * so the approval gesture on the board is the only point that can clear it.\n * Best-effort — every failure is a warning, never a rejected transition.\n */\nexport async function reconcileGithubAcceptanceLabels(\n github: GithubIntegration,\n sourceControl: SourceControlStorageHandle,\n input: ReconcileAcceptanceLabelsInput,\n): Promise<void> {\n const { item } = input;\n if (item.externalSource?.integrationId !== 'github' || item.externalSource.type !== 'issue') return;\n const repositoryId = item.workItem.metadata?.githubRepositoryId;\n const issueNumber = item.workItem.metadata?.githubIssueNumber;\n if (typeof repositoryId !== 'number' || typeof issueNumber !== 'number' || issueNumber < 1) return;\n\n try {\n const target = await resolveRepository(sourceControl, input.orgId, input.factoryProjectId, repositoryId);\n if (!target) return;\n await github.removeIssueLabel(target.installationId, target.slug, issueNumber, NEEDS_APPROVAL_LABEL);\n } catch (error) {\n // GitHub answers 404 when the label is not on the issue; nothing to clear.\n if ((error as { status?: number }).status === 404) return;\n console.warn(`[factory] could not clear \"${NEEDS_APPROVAL_LABEL}\" for work item ${item.id}:`, error);\n }\n}\n\nasync function resolveRepository(\n sourceControl: SourceControlStorageHandle,\n orgId: string,\n factoryProjectId: string,\n externalRepositoryId: number,\n): Promise<{ installationId: number; slug: string } | undefined> {\n for (const connection of await sourceControl.connections.list({ orgId, factoryProjectId })) {\n const installation = await sourceControl.installations.get({ orgId, id: connection.installationId });\n if (!installation) continue;\n for (const link of await sourceControl.projectRepositories.list({ orgId, connectionId: connection.id })) {\n const repository = await sourceControl.repositories.get({ orgId, id: link.repositoryId });\n if (!repository || Number(repository.externalId) !== externalRepositoryId) continue;\n const installationId = Number(installation.externalId);\n if (!Number.isInteger(installationId)) return undefined;\n return { installationId, slug: repository.slug };\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;AAiBA,eAAsB,gCACpB,QACA,eACA,OACe;CACf,MAAM,EAAE,SAAS;CACjB,IAAI,KAAK,gBAAgB,kBAAkB,YAAY,KAAK,eAAe,SAAS,SAAS;CAC7F,MAAM,eAAe,KAAK,SAAS,UAAU;CAC7C,MAAM,cAAc,KAAK,SAAS,UAAU;CAC5C,IAAI,OAAO,iBAAiB,YAAY,OAAO,gBAAgB,YAAY,cAAc,GAAG;CAE5F,IAAI;EACF,MAAM,SAAS,MAAM,kBAAkB,eAAe,MAAM,OAAO,MAAM,kBAAkB,YAAY;EACvG,IAAI,CAAC,QAAQ;EACb,MAAM,OAAO,iBAAiB,OAAO,gBAAgB,OAAO,MAAM,aAAa,oBAAoB;CACrG,SAAS,OAAO;EAEd,IAAK,MAA8B,WAAW,KAAK;EACnD,QAAQ,KAAK,8BAA8B,qBAAqB,kBAAkB,KAAK,GAAG,IAAI,KAAK;CACrG;AACF;AAEA,eAAe,kBACb,eACA,OACA,kBACA,sBAC+D;CAC/D,KAAK,MAAM,cAAc,MAAM,cAAc,YAAY,KAAK;EAAE;EAAO;CAAiB,CAAC,GAAG;EAC1F,MAAM,eAAe,MAAM,cAAc,cAAc,IAAI;GAAE;GAAO,IAAI,WAAW;EAAe,CAAC;EACnG,IAAI,CAAC,cAAc;EACnB,KAAK,MAAM,QAAQ,MAAM,cAAc,oBAAoB,KAAK;GAAE;GAAO,cAAc,WAAW;EAAG,CAAC,GAAG;GACvG,MAAM,aAAa,MAAM,cAAc,aAAa,IAAI;IAAE;IAAO,IAAI,KAAK;GAAa,CAAC;GACxF,IAAI,CAAC,cAAc,OAAO,WAAW,UAAU,MAAM,sBAAsB;GAC3E,MAAM,iBAAiB,OAAO,aAAa,UAAU;GACrD,IAAI,CAAC,OAAO,UAAU,cAAc,GAAG,OAAO,KAAA;GAC9C,OAAO;IAAE;IAAgB,MAAM,WAAW;GAAK;EACjD;CACF;AAEF"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';
|
|
2
2
|
export type GithubRuleOverrides = Partial<Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>>;
|
|
3
3
|
export type GithubEventRules = Readonly<Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>>;
|
|
4
|
-
declare function retriageGithubIssue(context: FactoryGithubRuleContext): {
|
|
5
|
-
readonly type: 'invokeSkill';
|
|
6
|
-
readonly idempotencyKey: `${string}:factory-triage`;
|
|
7
|
-
readonly role: 'triage';
|
|
8
|
-
readonly skillName: 'factory-triage';
|
|
9
|
-
readonly arguments: `Re-triage GitHub issue (${string}) after comment created.` | `Re-triage GitHub issue (${string}) after comment deleted.` | `Re-triage GitHub issue (${string}) after comment edited.` | `Re-triage GitHub issue (${string}) after issue body edited.` | `Re-triage GitHub issue (${string}) after issue title and body edited.` | `Re-triage GitHub issue (${string}) after issue title edited.`;
|
|
10
|
-
} | undefined;
|
|
11
4
|
declare function issueOpened(context: FactoryGithubRuleContext): {
|
|
12
5
|
readonly type: 'upsertLinkedWorkItem';
|
|
13
6
|
readonly idempotencyKey: `${string}:issue-intake`;
|
|
@@ -22,6 +15,7 @@ declare function issueOpened(context: FactoryGithubRuleContext): {
|
|
|
22
15
|
readonly githubIssueNumber: number;
|
|
23
16
|
readonly sourceCreatedAt?: string | undefined;
|
|
24
17
|
readonly author?: string | undefined;
|
|
18
|
+
readonly state: "closed" | "open";
|
|
25
19
|
readonly authorTrusted: boolean;
|
|
26
20
|
readonly autoStartCandidate: boolean;
|
|
27
21
|
readonly assignees: string[];
|
|
@@ -200,11 +194,11 @@ declare function reReviewUpdatedPullRequest(context: FactoryGithubRuleContext):
|
|
|
200
194
|
} | undefined;
|
|
201
195
|
export declare const defaultGithubRules: Readonly<{
|
|
202
196
|
issueOpened: typeof issueOpened;
|
|
203
|
-
issueEdited:
|
|
197
|
+
issueEdited: null;
|
|
204
198
|
issueClosed: typeof issueClosed;
|
|
205
|
-
issueCommentCreated:
|
|
206
|
-
issueCommentEdited:
|
|
207
|
-
issueCommentDeleted:
|
|
199
|
+
issueCommentCreated: null;
|
|
200
|
+
issueCommentEdited: null;
|
|
201
|
+
issueCommentDeleted: null;
|
|
208
202
|
pullRequestOpened: typeof pullRequestOpened;
|
|
209
203
|
pullRequestUpdated: typeof reReviewUpdatedPullRequest;
|
|
210
204
|
pullRequestCommentCreated: typeof addressPullRequestComment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/default-rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/default-rules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGjH,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,MAAM,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAChG,CAAC;AACF,MAAM,MAAM,gBAAgB,GAA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AC,OAAO,EAAE,wBAAwB;mBAe3D,YAAY;;;;;cASrB;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;EAgBF,CAAC;AAE9B,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAgBpF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isTerminalFactoryRuleStage } from "../../rules/types.js";
|
|
2
1
|
import { isPullRequestCard, pullRequestReviewPhase, reviewsPullRequest } from "../../boards/semantics.js";
|
|
3
2
|
import { hasRecordedVerdict } from "../../boards/pull-request-review.js";
|
|
4
3
|
import "../../boards/index.js";
|
|
@@ -23,22 +22,6 @@ function pullRequestCardBoard(context) {
|
|
|
23
22
|
function pullRequestCardNoun(context) {
|
|
24
23
|
return context.board === "review" ? "Review card" : "pull request card";
|
|
25
24
|
}
|
|
26
|
-
function retriageGithubIssue(context) {
|
|
27
|
-
if (!context.item || context.item.source !== "github-issue" || !context.item.url) return;
|
|
28
|
-
if (context.actor.type === "github" && context.actor.factoryAuthored) return;
|
|
29
|
-
if (context.board !== "work") return;
|
|
30
|
-
const stage = context.item.stages?.length === 1 ? context.item.stages[0] : void 0;
|
|
31
|
-
if (stage === "intake" || stage === "execute" || stage === "review") return;
|
|
32
|
-
if (isTerminalFactoryRuleStage(context.item.stages)) return;
|
|
33
|
-
const reason = context.event === "issueEdited" ? context.issueChange?.title && context.issueChange.body ? "issue title and body edited" : context.issueChange?.title ? "issue title edited" : "issue body edited" : context.event === "issueCommentDeleted" ? "comment deleted" : context.event === "issueCommentEdited" ? "comment edited" : "comment created";
|
|
34
|
-
return {
|
|
35
|
-
type: "invokeSkill",
|
|
36
|
-
idempotencyKey: `${context.ingress.id}:factory-triage`,
|
|
37
|
-
role: "triage",
|
|
38
|
-
skillName: "factory-triage",
|
|
39
|
-
arguments: `Re-triage GitHub issue (${context.item.url}) after ${reason}.`
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
25
|
function createdAfterFactory(createdAt, factoryCreatedAt) {
|
|
43
26
|
if (!createdAt) return false;
|
|
44
27
|
const sourceCreatedAt = Date.parse(createdAt);
|
|
@@ -71,7 +54,8 @@ function issueOpened(context) {
|
|
|
71
54
|
githubRepositoryId: context.repository.id,
|
|
72
55
|
githubIssueNumber: context.issue.number,
|
|
73
56
|
...context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {},
|
|
74
|
-
...githubActorLogin(context) ? { author: githubActorLogin(context) } : {},
|
|
57
|
+
...context.issue.author || githubActorLogin(context) ? { author: context.issue.author ?? githubActorLogin(context) } : {},
|
|
58
|
+
state: context.issue.state ?? "open",
|
|
75
59
|
authorTrusted: trustedGithubActor(context),
|
|
76
60
|
autoStartCandidate: trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),
|
|
77
61
|
assignees: context.issue.assignees ?? [],
|
|
@@ -266,11 +250,11 @@ function reReviewUpdatedPullRequest(context) {
|
|
|
266
250
|
}
|
|
267
251
|
const defaultGithubRules = Object.freeze({
|
|
268
252
|
issueOpened,
|
|
269
|
-
issueEdited:
|
|
253
|
+
issueEdited: null,
|
|
270
254
|
issueClosed,
|
|
271
|
-
issueCommentCreated:
|
|
272
|
-
issueCommentEdited:
|
|
273
|
-
issueCommentDeleted:
|
|
255
|
+
issueCommentCreated: null,
|
|
256
|
+
issueCommentEdited: null,
|
|
257
|
+
issueCommentDeleted: null,
|
|
274
258
|
pullRequestOpened,
|
|
275
259
|
pullRequestUpdated: reReviewUpdatedPullRequest,
|
|
276
260
|
pullRequestCommentCreated: addressPullRequestComment,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import { isPullRequestCard, pullRequestReviewPhase, reviewsPullRequest } from '../../boards/index.js';\nimport { hasRecordedVerdict } from '../../boards/pull-request-review.js';\nimport { requestsChangesVerdict } from '../../review-verdict.js';\nimport { recordExplicitRuleOverrides } from '../../rules/event-rules.js';\nimport { isTerminalFactoryRuleStage } from '../../rules/types.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\n/** The Work card whose session authored the pull request, as opposed to the PR's own card. */\nfunction authoringCard(context: FactoryGithubRuleContext): boolean {\n return context.board === 'work' && context.item !== undefined && !isPullRequestCard(context.item);\n}\n\n/** The board holding the PR's own card: Work for new cards, Review for cards filed before PRs moved to Work. */\nfunction pullRequestCardBoard(context: FactoryGithubRuleContext): 'work' | 'review' {\n return context.board === 'review' ? 'review' : 'work';\n}\n\nfunction pullRequestCardNoun(context: FactoryGithubRuleContext): string {\n return context.board === 'review' ? 'Review card' : 'pull request card';\n}\n\nfunction retriageGithubIssue(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.item.url) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n // The stage checks below use Work lane names; other boards opt in with their own rules.\n if (context.board !== 'work') return;\n // A card in Intake waits for a person to move it; talk on it starts nothing. Re-triage would\n // take over a card that is being built or reviewed.\n const stage = context.item.stages?.length === 1 ? context.item.stages[0] : undefined;\n if (stage === 'intake' || stage === 'execute' || stage === 'review') return;\n // A finished card has nothing left to triage; talk on a closed issue must not park a run on it.\n if (isTerminalFactoryRuleStage(context.item.stages)) return;\n\n const reason =\n context.event === 'issueEdited'\n ? context.issueChange?.title && context.issueChange.body\n ? 'issue title and body edited'\n : context.issueChange?.title\n ? 'issue title edited'\n : 'issue body edited'\n : context.event === 'issueCommentDeleted'\n ? 'comment deleted'\n : context.event === 'issueCommentEdited'\n ? 'comment edited'\n : 'comment created';\n return {\n type: 'invokeSkill',\n idempotencyKey: `${context.ingress.id}:factory-triage`,\n role: 'triage',\n skillName: 'factory-triage',\n arguments: `Re-triage GitHub issue (${context.item.url}) after ${reason}.`,\n } as const;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * Issue and pull request numbers repeat across repositories, so new cards are\n * keyed by repository. A card this repository already owns keeps its key —\n * including canonical `github-issue:N` / `github-pr:N` keys from before\n * scoping — but only when it is the same kind of source: pull request intake\n * runs with the authoring issue as `context.item`.\n */\nfunction githubSourceKey(\n context: FactoryGithubRuleContext,\n source: 'github-issue' | 'github-pr',\n itemNumber: number,\n): string {\n if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;\n return `github:${context.repository.id}:${source === 'github-issue' ? 'issue' : 'pull-request'}:${itemNumber}`;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue) return;\n // Everything arrives on the routed board's initial phase (Work › Intake when\n // no label route selects another board). Trust/timing stamps remain available\n // to custom board rules.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake?.board ?? 'work',\n source: 'github-issue',\n sourceKey: githubSourceKey(context, 'github-issue', context.issue.number),\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake?.initialPhase ?? 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(githubActorLogin(context) ? { author: githubActorLogin(context) } : {}),\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n // The card's board decides where a closed source sends it; boards that declare no\n // `sourceClosed` mapping keep the card where it is, as do cards already finished.\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n const target = canceled ? closure.canceled : closure.completed;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n } as const;\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n {\n idempotencyKey,\n autoStartCandidate,\n stage = 'intake',\n }: { idempotencyKey: string; autoStartCandidate: boolean; stage?: 'intake' | 'pr-review' },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'work',\n source: 'github-pr',\n sourceKey: githubSourceKey(context, 'github-pr', context.pullRequest.number),\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage,\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring Work item's own\n // evaluation only moves it out for review: Building means \"no pull request\n // yet\", Review means one is open. The card rests there through every round of\n // feedback — the builder is woken in place — until the merge closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (!authoringCard(context) || context.pullRequest.state !== 'open') return;\n if (!context.item.stages.includes('execute')) return;\n // Resolution can match a Work item by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: 'work',\n stage: 'review',\n } as const;\n }\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest?.merged) return;\n if (reviewsPullRequest(context)) {\n // The event is bound to the PR's own card: a merged PR is finished\n // review work, so always move the card to Done. The message only reaches\n // an active session (if any) — cards without one just move, instead of\n // failing retries against a binding that never existed.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: pullRequestCardBoard(context),\n stage: 'done',\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this ${pullRequestCardNoun(context)} was moved to Done. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n } as const;\n }\n // Custom boards define their own lifecycle and cannot accept a transition\n // targeting the built-in Work board. Let their custom rules handle the merge.\n if (context.board !== 'work') return;\n // Provenance bound the event to the originating Work item instead: the merge\n // is what finishes the work, so it closes the Work card alongside the PR's own card —\n // unless the card has since opened another pull request, which is still out.\n const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this Work card stays in Review until it merges.',\n } as const;\n }\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: 'work',\n stage: 'done',\n message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` },\n } as const;\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the Work item that authored the PR can act on the feedback. Provenance\n // binds the event there; the PR's own card seeing its posted review must not\n // react to it (that would loop the reviewer against itself).\n if (!authoringCard(context)) return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` (a review body with no verdict)\n // is how a reviewer leaves notes without blocking — only a verdict that asks\n // for changes should pull the author back in.\n if (context.review.state.toLowerCase() !== 'changes_requested') return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role: 'work',\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring Work session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the Work item that authored the PR — the\n // only session that can act on it. The PR's own card must not react to\n // comments on the PR it is reviewing.\n if (!authoringCard(context)) return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the Work agent's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role: 'work',\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || context.pullRequest.merged) return;\n if (!reviewsPullRequest(context)) return;\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in Reviewing forever.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: pullRequestCardBoard(context),\n stage: 'canceled',\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n `this ${pullRequestCardNoun(context)} was moved to Canceled.`,\n },\n } as const;\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && !reviewsPullRequest(context)) || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n stage: 'pr-review',\n });\n }\n // Already in Reviewing with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in Reviewing, so a fresh request\n // re-enters the stage to start another pass.\n const stage = pullRequestReviewPhase(context.board);\n const reviewing = context.item.stages.length === 1 && context.item.stages[0] === stage;\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: pullRequestCardBoard(context),\n stage,\n ...(reviewing ? { reenter: true } : {}),\n } as const;\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || !reviewsPullRequest(context)) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Intake has not started a review pass yet, so a push there is just more of\n // the code the first pass will read. A push to a card sitting in Reviewing is\n // different: it invalidates whatever that pass is reading, so re-enter the\n // stage to supersede it. `reviewPullRequest` cancels the stale run and picks\n // the right skill for the entry it sees.\n if (context.item.stages.some(stage => stage === 'intake')) return;\n // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n const stage = pullRequestReviewPhase(context.board);\n const alreadyReviewing = context.item.stages.some(current => current === stage);\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: pullRequestCardBoard(context),\n stage,\n // Re-entry is the point when the card is already Reviewing: the stage's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(alreadyReviewing ? { reenter: true } : {}),\n } as const;\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n issueEdited: retriageGithubIssue,\n issueClosed: issueClosed,\n issueCommentCreated: retriageGithubIssue,\n issueCommentEdited: retriageGithubIssue,\n issueCommentDeleted: retriageGithubIssue,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: pullRequestReviewSubmitted,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GithubEventRules, overrides);\n}\n"],"mappings":";;;;;;;;AAeA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,iBAAiB,SAAsE;CAC9F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,QAAQ,KAAA;AACjE;;AAGA,SAAS,cAAc,SAA4C;CACjE,OAAO,QAAQ,UAAU,UAAU,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAClG;;AAGA,SAAS,qBAAqB,SAAsD;CAClF,OAAO,QAAQ,UAAU,WAAW,WAAW;AACjD;AAEA,SAAS,oBAAoB,SAA2C;CACtE,OAAO,QAAQ,UAAU,WAAW,gBAAgB;AACtD;AAEA,SAAS,oBAAoB,SAAmC;CAC9D,IAAI,CAAC,QAAQ,QAAQ,QAAQ,KAAK,WAAW,kBAAkB,CAAC,QAAQ,KAAK,KAAK;CAClF,IAAI,QAAQ,MA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K,YAAW,YAAY,KAAK;CAC9E,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,qBAAqB,OAAO;EACnC;EAIA,GAAI,mBAAmB,EAAE,SAAS,KAAK,IAAI,CAAC;CAC9C;AACF;AAEA,MAAa,qBAAqB,OAAO,OAAO;CACjC;CACb,aAAa;CACA;CACb,qBAAqB;CACrB,oBAAoB;CACpB,qBAAqB;CACF;CACnB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CACA;CACT;CACA;AACrB,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
|
|
1
|
+
{"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import { isPullRequestCard, pullRequestReviewPhase, reviewsPullRequest } from '../../boards/index.js';\nimport { hasRecordedVerdict } from '../../boards/pull-request-review.js';\nimport { requestsChangesVerdict } from '../../review-verdict.js';\nimport { recordExplicitRuleOverrides } from '../../rules/event-rules.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\n/** The Work card whose session authored the pull request, as opposed to the PR's own card. */\nfunction authoringCard(context: FactoryGithubRuleContext): boolean {\n return context.board === 'work' && context.item !== undefined && !isPullRequestCard(context.item);\n}\n\n/** The board holding the PR's own card: Work for new cards, Review for cards filed before PRs moved to Work. */\nfunction pullRequestCardBoard(context: FactoryGithubRuleContext): 'work' | 'review' {\n return context.board === 'review' ? 'review' : 'work';\n}\n\nfunction pullRequestCardNoun(context: FactoryGithubRuleContext): string {\n return context.board === 'review' ? 'Review card' : 'pull request card';\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * Issue and pull request numbers repeat across repositories, so new cards are\n * keyed by repository. A card this repository already owns keeps its key —\n * including canonical `github-issue:N` / `github-pr:N` keys from before\n * scoping — but only when it is the same kind of source: pull request intake\n * runs with the authoring issue as `context.item`.\n */\nfunction githubSourceKey(\n context: FactoryGithubRuleContext,\n source: 'github-issue' | 'github-pr',\n itemNumber: number,\n): string {\n if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;\n return `github:${context.repository.id}:${source === 'github-issue' ? 'issue' : 'pull-request'}:${itemNumber}`;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue) return;\n // Everything arrives on the routed board's initial phase (Work › Intake when\n // no label route selects another board). Trust/timing stamps remain available\n // to custom board rules.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake?.board ?? 'work',\n source: 'github-issue',\n sourceKey: githubSourceKey(context, 'github-issue', context.issue.number),\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake?.initialPhase ?? 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(context.issue.author || githubActorLogin(context)\n ? { author: context.issue.author ?? githubActorLogin(context) }\n : {}),\n state: context.issue.state ?? 'open',\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n // The card's board decides where a closed source sends it; boards that declare no\n // `sourceClosed` mapping keep the card where it is, as do cards already finished.\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n const target = canceled ? closure.canceled : closure.completed;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n } as const;\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n {\n idempotencyKey,\n autoStartCandidate,\n stage = 'intake',\n }: { idempotencyKey: string; autoStartCandidate: boolean; stage?: 'intake' | 'pr-review' },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'work',\n source: 'github-pr',\n sourceKey: githubSourceKey(context, 'github-pr', context.pullRequest.number),\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage,\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring Work item's own\n // evaluation only moves it out for review: Building means \"no pull request\n // yet\", Review means one is open. The card rests there through every round of\n // feedback — the builder is woken in place — until the merge closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (!authoringCard(context) || context.pullRequest.state !== 'open') return;\n if (!context.item.stages.includes('execute')) return;\n // Resolution can match a Work item by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: 'work',\n stage: 'review',\n } as const;\n }\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest?.merged) return;\n if (reviewsPullRequest(context)) {\n // The event is bound to the PR's own card: a merged PR is finished\n // review work, so always move the card to Done. The message only reaches\n // an active session (if any) — cards without one just move, instead of\n // failing retries against a binding that never existed.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: pullRequestCardBoard(context),\n stage: 'done',\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this ${pullRequestCardNoun(context)} was moved to Done. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n } as const;\n }\n // Custom boards define their own lifecycle and cannot accept a transition\n // targeting the built-in Work board. Let their custom rules handle the merge.\n if (context.board !== 'work') return;\n // Provenance bound the event to the originating Work item instead: the merge\n // is what finishes the work, so it closes the Work card alongside the PR's own card —\n // unless the card has since opened another pull request, which is still out.\n const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this Work card stays in Review until it merges.',\n } as const;\n }\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: 'work',\n stage: 'done',\n message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` },\n } as const;\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the Work item that authored the PR can act on the feedback. Provenance\n // binds the event there; the PR's own card seeing its posted review must not\n // react to it (that would loop the reviewer against itself).\n if (!authoringCard(context)) return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` (a review body with no verdict)\n // is how a reviewer leaves notes without blocking — only a verdict that asks\n // for changes should pull the author back in.\n if (context.review.state.toLowerCase() !== 'changes_requested') return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role: 'work',\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring Work session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the Work item that authored the PR — the\n // only session that can act on it. The PR's own card must not react to\n // comments on the PR it is reviewing.\n if (!authoringCard(context)) return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the Work agent's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role: 'work',\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || context.pullRequest.merged) return;\n if (!reviewsPullRequest(context)) return;\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in Reviewing forever.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: pullRequestCardBoard(context),\n stage: 'canceled',\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n `this ${pullRequestCardNoun(context)} was moved to Canceled.`,\n },\n } as const;\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && !reviewsPullRequest(context)) || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n stage: 'pr-review',\n });\n }\n // Already in Reviewing with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in Reviewing, so a fresh request\n // re-enters the stage to start another pass.\n const stage = pullRequestReviewPhase(context.board);\n const reviewing = context.item.stages.length === 1 && context.item.stages[0] === stage;\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: pullRequestCardBoard(context),\n stage,\n ...(reviewing ? { reenter: true } : {}),\n } as const;\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || !reviewsPullRequest(context)) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Intake has not started a review pass yet, so a push there is just more of\n // the code the first pass will read. A push to a card sitting in Reviewing is\n // different: it invalidates whatever that pass is reading, so re-enter the\n // stage to supersede it. `reviewPullRequest` cancels the stale run and picks\n // the right skill for the entry it sees.\n if (context.item.stages.some(stage => stage === 'intake')) return;\n // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n const stage = pullRequestReviewPhase(context.board);\n const alreadyReviewing = context.item.stages.some(current => current === stage);\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: pullRequestCardBoard(context),\n stage,\n // Re-entry is the point when the card is already Reviewing: the stage's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(alreadyReviewing ? { reenter: true } : {}),\n } as const;\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueEdited: null,\n issueClosed: issueClosed,\n issueCommentCreated: null,\n issueCommentEdited: null,\n issueCommentDeleted: null,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: pullRequestReviewSubmitted,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GithubEventRules, overrides);\n}\n"],"mappings":";;;;;;;AAcA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAE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,EAAE,SAAS,KAAK,IAAI,CAAC;CAC9C;AACF;AAEA,MAAa,qBAAqB,OAAO,OAAO;CACjC;CAGb,aAAa;CACA;CACb,qBAAqB;CACrB,oBAAoB;CACpB,qBAAqB;CACF;CACnB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CACA;CACT;CACA;AACrB,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
|
|
@@ -96,20 +96,22 @@ function createGithubIssueReconciler(options, fetchIssue, listOpenIssues) {
|
|
|
96
96
|
} catch (error) {
|
|
97
97
|
recordFailure(repository, error, issueNumber);
|
|
98
98
|
}
|
|
99
|
-
if (state.labels !== void 0 && items.some((item) => Array.isArray(item.metadata?.labels) && !sameStrings(item.
|
|
99
|
+
if (state.labels !== void 0 && items.some((item) => Array.isArray(item.workItem.metadata?.labels) && !sameStrings(item.workItem.labels, state.labels))) {
|
|
100
100
|
await rules.ingest(reconciledIssueRelabeledEvent(repository, issueNumber, state));
|
|
101
101
|
summary.relabeled += 1;
|
|
102
102
|
}
|
|
103
103
|
for (const item of items) {
|
|
104
|
-
const current =
|
|
104
|
+
const current = {
|
|
105
|
+
...item.workItem.metadata,
|
|
106
|
+
...item.metadata
|
|
107
|
+
};
|
|
105
108
|
const trustStale = authorTrusted !== void 0 && current.authorTrusted !== authorTrusted;
|
|
106
109
|
if (!(trustStale || current.githubRepositoryId !== desiredMetadata.githubRepositoryId || current.githubIssueNumber !== desiredMetadata.githubIssueNumber || current.state !== desiredMetadata.state || state.author !== void 0 && current.author !== state.author || state.assignees !== void 0 && !sameStrings(current.assignees, state.assignees) || state.labels !== void 0 && !sameStrings(current.labels, state.labels))) continue;
|
|
107
|
-
await options.storage.
|
|
110
|
+
await options.storage.syncCard({
|
|
108
111
|
orgId: item.orgId,
|
|
109
112
|
id: item.id,
|
|
110
113
|
userId: "factory-rule-dispatcher",
|
|
111
114
|
patch: { metadata: {
|
|
112
|
-
...current,
|
|
113
115
|
...desiredMetadata,
|
|
114
116
|
...trustStale ? { authorTrusted } : {}
|
|
115
117
|
} }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/github/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport type { IntegrationContext } from '../base.js';\nimport {\n githubRulesOptions,\n reconcilableIssueNumber,\n reconciledIssueClosedEvent,\n reconciledIssueOpenedEvent,\n reconciledIssueRelabeledEvent,\n RECONCILE_ERROR_SAMPLE_LIMIT,\n sameStrings,\n sweepTrustLookup,\n GithubRules,\n} from './rules.js';\nimport type {\n GithubIssueFetcher,\n GithubOpenIssueLister,\n GithubRulesIntegration,\n GithubRulesOptions,\n ReconcileRepository,\n} from './rules.js';\n\nexport interface GithubIssueReconcileSummary {\n /** Repositories included in the sweep. */\n repositories: number;\n /** Issue cards whose live state was fetched. */\n checked: number;\n /** Open issues with metadata patches. */\n updated: number;\n /** Closed issues replayed through the rules ingress. */\n closed: number;\n /** Open issues whose changed labels were replayed through the rules ingress. */\n relabeled: number;\n /** Open issues with no Work card replayed as `opened` through the rules ingress. */\n created: number;\n /** Errors encountered during the sweep. */\n failed: number;\n /** Error samples with context. */\n errors: Array<{ repository: string; issueNumber?: number; error: string }>;\n}\n\nexport type GithubIssueReconciler = (repositories: ReconcileRepository[]) => Promise<GithubIssueReconcileSummary>;\n\nexport function createGithubIssueReconciler(\n options: GithubRulesOptions,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler {\n const rules = new GithubRules(options);\n return async repositories => {\n const summary: GithubIssueReconcileSummary = {\n repositories: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n relabeled: 0,\n created: 0,\n failed: 0,\n errors: [],\n };\n const recordFailure = (repository: ReconcileRepository, error: unknown, issueNumber?: number) => {\n summary.failed += 1;\n if (summary.errors.length < RECONCILE_ERROR_SAMPLE_LIMIT) {\n summary.errors.push({\n repository: repository.fullName,\n ...(issueNumber === undefined ? {} : { issueNumber }),\n error: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n for (const repository of repositories) {\n summary.repositories += 1;\n const authorTrust = sweepTrustLookup(options.github, repository);\n\n try {\n const projects = await options.sourceControl.projectRepositories.listByExternalRepository({\n installationExternalId: String(repository.installationId),\n repositoryExternalId: String(repository.id),\n });\n if (projects.length === 0) continue;\n\n // Collect issue cards: number -> items (skip terminal stages)\n const itemsByNumber = new Map<number, import('../../storage/domains/work-items/base.js').WorkItemRow[]>();\n // Every issue with any card, terminal included: a finished card must\n // not be re-minted by missed-open discovery.\n const carded = new Set<number>();\n\n for (const project of projects) {\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (!issueNumber) continue;\n carded.add(issueNumber);\n if (workItemPhaseSemantics(options.boards, item)?.kind === 'terminal') continue;\n let list = itemsByNumber.get(issueNumber);\n if (!list) {\n list = [];\n itemsByNumber.set(issueNumber, list);\n }\n list.push(item);\n }\n }\n\n // Missed-open discovery: an `opened` delivery that never reached the\n // ingress leaves no card for the sweeps above to repair. Only issues\n // filed after the repository was linked are replayed, so linking a\n // repository never backfills its existing backlog.\n if (listOpenIssues) {\n const linkedAt = Math.min(...projects.map(project => project.projectRepository.createdAt.getTime()));\n const openIssues = await listOpenIssues({\n installationId: repository.installationId,\n repository: repository.fullName,\n });\n for (const issue of openIssues) {\n if (carded.has(issue.number)) continue;\n const createdAt = issue.createdAt ? Date.parse(issue.createdAt) : Number.NaN;\n if (!Number.isFinite(createdAt) || createdAt < linkedAt) continue;\n try {\n const result = await rules.ingest(reconciledIssueOpenedEvent(repository, issue.number, issue));\n if (result.status === 'committed') summary.created += 1;\n } catch (error) {\n recordFailure(repository, error, issue.number);\n }\n }\n }\n\n // Fetch and reconcile each unique issue\n for (const [issueNumber, items] of itemsByNumber) {\n try {\n const state = await fetchIssue({\n installationId: repository.installationId,\n repository: repository.fullName,\n number: issueNumber,\n });\n if (!state) continue; // missing or PR-backed\n summary.checked += 1;\n\n // Close detection: replay through rules ingress\n if (state.state === 'closed') {\n await rules.ingest(reconciledIssueClosedEvent(repository, issueNumber, state));\n summary.closed += 1;\n continue; // card transitions, skip metadata patch\n }\n\n // Metadata sync for open issues\n const desiredMetadata = {\n githubRepositoryId: repository.id,\n githubIssueNumber: issueNumber,\n state: 'open' as const,\n ...(state.author === undefined ? {} : { author: state.author }),\n ...(state.assignees === undefined ? {} : { assignees: state.assignees }),\n ...(state.labels === undefined ? {} : { labels: state.labels }),\n };\n // Re-stamped on every sweep so revoked write access reads untrusted\n // within one cycle; a failed lookup keeps the last stamp and retries.\n let authorTrusted: boolean | undefined;\n if (state.author !== undefined) {\n try {\n authorTrusted = await authorTrust(state.author);\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n\n // Label drift decides where the card belongs, and the rule that owns\n // that decision has to run again — mirrored from the `labeled` /\n // `unlabeled` webhook, replayed here so a label Factory never saw a\n // delivery for still re-places the card. Replayed before the\n // metadata patch, so the ingress sees the drift it acts on.\n if (\n state.labels !== undefined &&\n items.some(\n item => Array.isArray(item.metadata?.labels) && !sameStrings(item.metadata.labels, state.labels),\n )\n ) {\n await rules.ingest(reconciledIssueRelabeledEvent(repository, issueNumber, state));\n summary.relabeled += 1;\n }\n\n for (const item of items) {\n const current = item.metadata ?? {};\n const trustStale = authorTrusted !== undefined && current.authorTrusted !== authorTrusted;\n const metadataChanged =\n trustStale ||\n current.githubRepositoryId !== desiredMetadata.githubRepositoryId ||\n current.githubIssueNumber !== desiredMetadata.githubIssueNumber ||\n current.state !== desiredMetadata.state ||\n (state.author !== undefined && current.author !== state.author) ||\n (state.assignees !== undefined && !sameStrings(current.assignees, state.assignees)) ||\n (state.labels !== undefined && !sameStrings(current.labels, state.labels));\n\n if (!metadataChanged) continue;\n\n await options.storage.update({\n orgId: item.orgId,\n id: item.id,\n userId: 'factory-rule-dispatcher',\n patch: { metadata: { ...current, ...desiredMetadata, ...(trustStale ? { authorTrusted } : {}) } },\n });\n summary.updated += 1;\n }\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n } catch (error) {\n recordFailure(repository, error);\n }\n }\n\n return summary;\n };\n}\n\nexport function attachGithubIssueReconciler(\n github: GithubRulesIntegration,\n context: IntegrationContext,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler | undefined {\n if (!context.runtime) return undefined;\n const options = githubRulesOptions(github, context);\n if (!options) return undefined;\n return createGithubIssueReconciler(options, fetchIssue, listOpenIssues);\n}\n"],"mappings":";;;;AA0CA,SAAgB,4BACd,SACA,YACA,gBACuB;CACvB,MAAM,QAAQ,IAAI,YAAY,OAAO;CACrC,OAAO,OAAM,iBAAgB;EAC3B,MAAM,UAAuC;GAC3C,cAAc;GACd,SAAS;GACT,SAAS;GACT,QAAQ;GACR,WAAW;GACX,SAAS;GACT,QAAQ;GACR,QAAQ,CAAC;EACX;EACA,MAAM,iBAAiB,YAAiC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AK,SAAS,QAAQ,MAAM,MAAM,CACjG,GACA;MACA,MAAM,MAAM,OAAO,8BAA8B,YAAY,aAAa,KAAK,CAAC;MAChF,QAAQ,aAAa;KACvB;KAEA,KAAK,MAAM,QAAQ,OAAO;MACxB,MAAM,UAAU,KAAK,YAAY,CAAC;MAClC,MAAM,aAAa,kBAAkB,KAAA,KAAa,QAAQ,kBAAkB;MAU5E,IAAI,EARF,cACA,QAAQ,uBAAuB,gBAAgB,sBAC/C,QAAQ,sBAAsB,gBAAgB,qBAC9C,QAAQ,UAAU,gBAAgB,SACjC,MAAM,WAAW,KAAA,KAAa,QAAQ,WAAW,MAAM,UACvD,MAAM,cAAc,KAAA,KAAa,CAAC,YAAY,QAAQ,WAAW,MAAM,SAAS,KAChF,MAAM,WAAW,KAAA,KAAa,CAAC,YAAY,QAAQ,QAAQ,MAAM,MAAM,IAEpD;MAEtB,MAAM,QAAQ,QAAQ,OAAO;OAC3B,OAAO,KAAK;OACZ,IAAI,KAAK;OACT,QAAQ;OACR,OAAO,EAAE,UAAU;QAAE,GAAG;QAAS,GAAG;QAAiB,GAAI,aAAa,EAAE,cAAc,IAAI,CAAC;OAAG,EAAE;MAClG,CAAC;MACD,QAAQ,WAAW;KACrB;IACF,SAAS,OAAO;KACd,cAAc,YAAY,OAAO,WAAW;IAC9C;GAEJ,SAAS,OAAO;IACd,cAAc,YAAY,KAAK;GACjC;EACF;EAEA,OAAO;CACT;AACF;AAEA,SAAgB,4BACd,QACA,SACA,YACA,gBACmC;CACnC,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,UAAU,mBAAmB,QAAQ,OAAO;CAClD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,OAAO,4BAA4B,SAAS,YAAY,cAAc;AACxE"}
|
|
1
|
+
{"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/github/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport type { IntegrationContext } from '../base.js';\nimport {\n githubRulesOptions,\n reconcilableIssueNumber,\n reconciledIssueClosedEvent,\n reconciledIssueOpenedEvent,\n reconciledIssueRelabeledEvent,\n RECONCILE_ERROR_SAMPLE_LIMIT,\n sameStrings,\n sweepTrustLookup,\n GithubRules,\n} from './rules.js';\nimport type {\n GithubIssueFetcher,\n GithubOpenIssueLister,\n GithubRulesIntegration,\n GithubRulesOptions,\n ReconcileRepository,\n} from './rules.js';\n\nexport interface GithubIssueReconcileSummary {\n /** Repositories included in the sweep. */\n repositories: number;\n /** Issue cards whose live state was fetched. */\n checked: number;\n /** Open issues with metadata patches. */\n updated: number;\n /** Closed issues replayed through the rules ingress. */\n closed: number;\n /** Open issues whose changed labels were replayed through the rules ingress. */\n relabeled: number;\n /** Open issues with no Work card replayed as `opened` through the rules ingress. */\n created: number;\n /** Errors encountered during the sweep. */\n failed: number;\n /** Error samples with context. */\n errors: Array<{ repository: string; issueNumber?: number; error: string }>;\n}\n\nexport type GithubIssueReconciler = (repositories: ReconcileRepository[]) => Promise<GithubIssueReconcileSummary>;\n\nexport function createGithubIssueReconciler(\n options: GithubRulesOptions,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler {\n const rules = new GithubRules(options);\n return async repositories => {\n const summary: GithubIssueReconcileSummary = {\n repositories: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n relabeled: 0,\n created: 0,\n failed: 0,\n errors: [],\n };\n const recordFailure = (repository: ReconcileRepository, error: unknown, issueNumber?: number) => {\n summary.failed += 1;\n if (summary.errors.length < RECONCILE_ERROR_SAMPLE_LIMIT) {\n summary.errors.push({\n repository: repository.fullName,\n ...(issueNumber === undefined ? {} : { issueNumber }),\n error: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n for (const repository of repositories) {\n summary.repositories += 1;\n const authorTrust = sweepTrustLookup(options.github, repository);\n\n try {\n const projects = await options.sourceControl.projectRepositories.listByExternalRepository({\n installationExternalId: String(repository.installationId),\n repositoryExternalId: String(repository.id),\n });\n if (projects.length === 0) continue;\n\n // Collect issue cards: number -> items (skip terminal stages)\n const itemsByNumber = new Map<number, import('../../storage/domains/work-items/base.js').Card[]>();\n // Every issue with any card, terminal included: a finished card must\n // not be re-minted by missed-open discovery.\n const carded = new Set<number>();\n\n for (const project of projects) {\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (!issueNumber) continue;\n carded.add(issueNumber);\n if (workItemPhaseSemantics(options.boards, item)?.kind === 'terminal') continue;\n let list = itemsByNumber.get(issueNumber);\n if (!list) {\n list = [];\n itemsByNumber.set(issueNumber, list);\n }\n list.push(item);\n }\n }\n\n // Missed-open discovery: an `opened` delivery that never reached the\n // ingress leaves no card for the sweeps above to repair. Only issues\n // filed after the repository was linked are replayed, so linking a\n // repository never backfills its existing backlog.\n if (listOpenIssues) {\n const linkedAt = Math.min(...projects.map(project => project.projectRepository.createdAt.getTime()));\n const openIssues = await listOpenIssues({\n installationId: repository.installationId,\n repository: repository.fullName,\n });\n for (const issue of openIssues) {\n if (carded.has(issue.number)) continue;\n const createdAt = issue.createdAt ? Date.parse(issue.createdAt) : Number.NaN;\n if (!Number.isFinite(createdAt) || createdAt < linkedAt) continue;\n try {\n const result = await rules.ingest(reconciledIssueOpenedEvent(repository, issue.number, issue));\n if (result.status === 'committed') summary.created += 1;\n } catch (error) {\n recordFailure(repository, error, issue.number);\n }\n }\n }\n\n // Fetch and reconcile each unique issue\n for (const [issueNumber, items] of itemsByNumber) {\n try {\n const state = await fetchIssue({\n installationId: repository.installationId,\n repository: repository.fullName,\n number: issueNumber,\n });\n if (!state) continue; // missing or PR-backed\n summary.checked += 1;\n\n // Close detection: replay through rules ingress\n if (state.state === 'closed') {\n await rules.ingest(reconciledIssueClosedEvent(repository, issueNumber, state));\n summary.closed += 1;\n continue; // card transitions, skip metadata patch\n }\n\n // Metadata sync for open issues\n const desiredMetadata = {\n githubRepositoryId: repository.id,\n githubIssueNumber: issueNumber,\n state: 'open' as const,\n ...(state.author === undefined ? {} : { author: state.author }),\n ...(state.assignees === undefined ? {} : { assignees: state.assignees }),\n ...(state.labels === undefined ? {} : { labels: state.labels }),\n };\n // Re-stamped on every sweep so revoked write access reads untrusted\n // within one cycle; a failed lookup keeps the last stamp and retries.\n let authorTrusted: boolean | undefined;\n if (state.author !== undefined) {\n try {\n authorTrusted = await authorTrust(state.author);\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n\n // Label drift decides where the card belongs, and the rule that owns\n // that decision has to run again — mirrored from the `labeled` /\n // `unlabeled` webhook, replayed here so a label Factory never saw a\n // delivery for still re-places the card. Replayed before the\n // metadata patch, so the ingress sees the drift it acts on.\n if (\n state.labels !== undefined &&\n items.some(\n item => Array.isArray(item.workItem.metadata?.labels) && !sameStrings(item.workItem.labels, state.labels),\n )\n ) {\n await rules.ingest(reconciledIssueRelabeledEvent(repository, issueNumber, state));\n summary.relabeled += 1;\n }\n\n for (const item of items) {\n const current = { ...item.workItem.metadata, ...item.metadata };\n const trustStale = authorTrusted !== undefined && current.authorTrusted !== authorTrusted;\n const metadataChanged =\n trustStale ||\n current.githubRepositoryId !== desiredMetadata.githubRepositoryId ||\n current.githubIssueNumber !== desiredMetadata.githubIssueNumber ||\n current.state !== desiredMetadata.state ||\n (state.author !== undefined && current.author !== state.author) ||\n (state.assignees !== undefined && !sameStrings(current.assignees, state.assignees)) ||\n (state.labels !== undefined && !sameStrings(current.labels, state.labels));\n\n if (!metadataChanged) continue;\n\n await options.storage.syncCard({\n orgId: item.orgId,\n id: item.id,\n userId: 'factory-rule-dispatcher',\n patch: { metadata: { ...desiredMetadata, ...(trustStale ? { authorTrusted } : {}) } },\n });\n summary.updated += 1;\n }\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n } catch (error) {\n recordFailure(repository, error);\n }\n }\n\n return summary;\n };\n}\n\nexport function attachGithubIssueReconciler(\n github: GithubRulesIntegration,\n context: IntegrationContext,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler | undefined {\n if (!context.runtime) return undefined;\n const options = githubRulesOptions(github, context);\n if (!options) return undefined;\n return createGithubIssueReconciler(options, fetchIssue, listOpenIssues);\n}\n"],"mappings":";;;;AA0CA,SAAgB,4BACd,SACA,YACA,gBACuB;CACvB,MAAM,QAAQ,IAAI,YAAY,OAAO;CACrC,OAAO,OAAM,iBAAgB;EAC3B,MAAM,UAAuC;GAC3C,cAAc;GACd,SAAS;GACT,SAAS;GACT,QAAQ;GACR,WAAW;GACX,SAAS;GACT,QAAQ;GACR,QAAQ,CAAC;EACX;EACA,MAAM,iBAAiB,YAAiC,OAAgB,gBAAyB;GAC/F,QAAQ,UAAU;GAClB,IAAI,QAAQ,OAAO,SAAA,GACjB,QAAQ,OAAO,KAAK;IAClB,YAAY,WAAW;IACvB,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY;IACnD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAC9D,CAAC;EAEL;EAEA,KAAK,MAAM,cAAc,cAAc;GACrC,QAAQ,gBAAgB;GACxB,MAAM,cAAc,iBAAiB,QAAQ,QAAQ,UAAU;GAE/D,IAAI;IACF,MAAM,WAAW,MAAM,QAAQ,cAAc,oBAAoB,yBAAyB;KACxF,wBAAwB,OAAO,WAAW,cAAc;KACxD,sBAAsB,OAAO,WAAW,EAAE;IAC5C,CAAC;IACD,IAAI,SAAS,WAAW,GAAG;IAG3B,MAAM,gCAAgB,IAAI,IAAuE;IAGjG,MAAM,yBAAS,IAAI,IAAY;IAE/B,KAAK,MAAM,WAAW,UAAU;KAC9B,MAAM,QAAQ,MAAM,QAAQ,QAAQ,KAAK;MACvC,OAAO,QAAQ;MACf,kBAAkB,QAAQ;KAC5B,CAAC;KACD,KAAK,MAAM,QAAQ,OAAO;MACxB,MAAM,c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E;MACtF,CAAC;MACD,QAAQ,WAAW;KACrB;IACF,SAAS,OAAO;KACd,cAAc,YAAY,OAAO,WAAW;IAC9C;GAEJ,SAAS,OAAO;IACd,cAAc,YAAY,KAAK;GACjC;EACF;EAEA,OAAO;CACT;AACF;AAEA,SAAgB,4BACd,QACA,SACA,YACA,gBACmC;CACnC,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,UAAU,mBAAmB,QAAQ,OAAO;CAClD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,OAAO,4BAA4B,SAAS,YAAY,cAAc;AACxE"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { FactoryRuleJsonValue } from '../../rules/types.js';
|
|
2
2
|
import type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';
|
|
3
3
|
import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
|
|
4
|
-
import type { FactoryRunBindingRecord,
|
|
4
|
+
import type { FactoryRunBindingRecord, Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';
|
|
5
5
|
import type { GithubIntegration } from './integration.js';
|
|
6
6
|
export interface RecordFactoryPullRequestProvenanceInput {
|
|
7
7
|
binding: FactoryRunBindingRecord;
|
|
8
|
-
item:
|
|
8
|
+
item: Card;
|
|
9
9
|
assistantMessageId: string;
|
|
10
10
|
toolCallId: string;
|
|
11
11
|
toolName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/provenance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"provenance.d.ts","source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AY,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAClG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYxB;AAED,wBAAsB,kCAAkC,CACtD,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,0BAA0B,EACzC,kBAAkB,EAAE,wBAAwB,CAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,gCAAgC,CACjC,EACD,SAAS,EAAE,gBAAgB,EAC3B,KAAK,EAAE,uCAAuC,GAC7C,OAAO,CAAC,IAAI,CAAC,CA0Gf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord,
|
|
1
|
+
{"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord, Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\nimport { cardBelongsToRepository } from './rules.js';\nimport { parseCreatedPullRequest } from './session-subscriptions.js';\n\nexport interface RecordFactoryPullRequestProvenanceInput {\n binding: FactoryRunBindingRecord;\n item: Card;\n assistantMessageId: string;\n toolCallId: string;\n toolName: string;\n toolInput: FactoryRuleJsonValue;\n toolResult: FactoryRuleJsonValue;\n status: 'success' | 'error';\n}\n\nexport interface FactoryPullRequestProvenanceData {\n kind: 'factory-pr-provenance';\n bindingId: string;\n workItemId: string;\n factoryProjectId: string;\n repositoryId: number;\n pullRequestNumber: number;\n pullRequestUrl: string;\n assistantMessageId: string;\n toolCallId: string;\n}\n\nexport async function resolveFactoryPullRequestParentWorkItemId(\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n input: { orgId: string; factoryProjectId: string; repositoryId: number; pullRequestNumber: number },\n): Promise<string | null> {\n const targetKey = `factory-pr-provenance:${input.repositoryId}:${input.pullRequestNumber}`;\n // Provenance is scoped to the Factory project whose run authored the PR.\n // Rows from a sibling project in the same org — or legacy rows without the\n // project stamp — fail closed rather than linking another project's card.\n const provenance = (await integrationStorage.subscriptions.listByTarget(targetKey, { status: 'active' })).find(\n row =>\n row.orgId === input.orgId &&\n row.data?.kind === 'factory-pr-provenance' &&\n row.data.factoryProjectId === input.factoryProjectId,\n );\n return provenance?.data?.workItemId ?? null;\n}\n\nexport async function recordFactoryPullRequestProvenance(\n github: GithubIntegration,\n sourceControl: SourceControlStorageHandle,\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n workItems: WorkItemsStorage,\n input: RecordFactoryPullRequestProvenanceInput,\n): Promise<void> {\n if (input.status !== 'success' || input.item.externalSource?.type === 'pull-request') return;\n const url = parseCreatedPullRequest({\n toolName: input.toolName,\n input: input.toolInput,\n output: input.toolResult,\n });\n if (!url) return;\n\n try {\n const match = url.match(/^https:\\/\\/github\\.com\\/([^/]+\\/[^/]+)\\/pull\\/(\\d+)\\/?$/i);\n if (!match) return;\n const repositorySlug = match[1]!;\n let repositoryId: number | undefined;\n let installationId: number | undefined;\n for (const connection of await sourceControl.connections.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })) {\n const installation = await sourceControl.installations.get({\n orgId: input.binding.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const link of await sourceControl.projectRepositories.list({\n orgId: input.binding.orgId,\n connectionId: connection.id,\n })) {\n const repository = await sourceControl.repositories.get({ orgId: input.binding.orgId, id: link.repositoryId });\n if (!repository || repository.slug.toLowerCase() !== repositorySlug.toLowerCase()) continue;\n repositoryId = Number(repository.externalId);\n installationId = Number(installation.externalId);\n break;\n }\n if (repositoryId !== undefined) break;\n }\n const pullRequestNumber = Number(match[2]);\n const [owner, repo] = repositorySlug.split('/');\n if (\n !owner ||\n !repo ||\n repositoryId === undefined ||\n installationId === undefined ||\n !Number.isInteger(repositoryId) ||\n !Number.isInteger(installationId) ||\n !Number.isInteger(pullRequestNumber) ||\n pullRequestNumber < 1\n )\n return;\n const targetKey = `factory-pr-provenance:${repositoryId}:${pullRequestNumber}`;\n // Dedupe within the authoring project only: a sibling project's row must\n // not block this project from recording its own provenance.\n if (\n (await integrationStorage.subscriptions.listByTarget(targetKey)).some(\n row => row.orgId === input.binding.orgId && row.data?.factoryProjectId === input.binding.factoryProjectId,\n )\n ) {\n return;\n }\n\n const { data } = await github\n .getInstallationOctokit(installationId)\n .pulls.get({ owner, repo, pull_number: pullRequestNumber });\n if (data.base.repo.id !== repositoryId || data.number !== pullRequestNumber || data.html_url !== url) return;\n\n await integrationStorage.subscriptions.create({\n orgId: input.binding.orgId,\n targetKey,\n threadId: input.binding.threadId,\n status: 'active',\n data: {\n kind: 'factory-pr-provenance',\n bindingId: input.binding.id,\n workItemId: input.item.id,\n factoryProjectId: input.binding.factoryProjectId,\n repositoryId,\n pullRequestNumber,\n pullRequestUrl: url,\n assistantMessageId: input.assistantMessageId,\n toolCallId: input.toolCallId,\n },\n });\n\n const reviewItem = (\n await workItems.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })\n ).find(\n item =>\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n (item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}` ||\n (item.externalSource.externalId === `github-pr:${pullRequestNumber}` &&\n cardBelongsToRepository(item, repositoryId, repositorySlug))),\n );\n if (reviewItem) {\n await workItems.setParentWorkItemIfMissing({\n orgId: input.binding.orgId,\n id: reviewItem.id,\n userId: 'factory-pr-provenance',\n parentWorkItemId: input.item.id,\n });\n }\n } catch {\n }\n}\n"],"mappings":";;;AA+BA,eAAsB,0CACpB,oBAKA,OACwB;CACxB,MAAM,YAAY,yBAAyB,MAAM,aAAa,GAAG,MAAM;CAUvE,QANoB,MAAM,mBAAmB,cAAc,aAAa,WAAW,EAAE,QAAQ,SAAS,CAAC,EAAA,CAAG,MACxG,QACE,IAAI,UAAU,MAAM,SACpB,IAAI,MAAM,SAAS,2BACnB,IAAI,KAAK,qBAAqB,MAAM,gBAExB,CAAC,EAAE,MAAM,cAAc;AACzC;AAEA,eAAsB,mCACpB,QACA,eACA,oBAKA,WACA,OACe;CACf,IAAI,MAAM,WAAW,aAAa,MAAM,KAAK,gBAAgB,SAAS,gBAAgB;CACtF,MAAM,MAAM,wBAAwB;EAClC,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,QAAQ,MAAM;CAChB,CAAC;CACD,IAAI,CAAC,KAAK;CAEV,IAAI;EACF,MAAM,QAAQ,IAAI,MAAM,0DAA0D;EAClF,IAAI,CAAC,OAAO;EACZ,MAAM,iBAAiB,MAAM;EAC7B,IAAI;EACJ,IAAI;EACJ,KAAK,MAAM,cAAc,MAAM,cAAc,YAAY,KAAK;GAC5D,OAAO,MAAM,QAAQ;GACrB,kBAAkB,MAAM,QAAQ;EAClC,CAAC,GAAG;GACF,MAAM,eAAe,MAAM,cAAc,cAAc,IAAI;IACzD,OAAO,MAAM,QAAQ;IACrB,IAAI,WAAW;GACjB,CAAC;GACD,IAAI,CAAC,cAAc;GACnB,KAAK,MAAM,QAAQ,MAAM,cAAc,oBAAoB,KAAK;IAC9D,OAAO,MAAM,QAAQ;IACrB,cAAc,WAAW;GAC3B,CAAC,GAAG;IACF,MAAM,aAAa,MAAM,cAAc,aAAa,IAAI;KAAE,OAAO,MAAM,QAAQ;K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AkF;IAClF,SAAS,CAAC,EAAE,IAAI,CACd,OAAO,0CAA0C,EAAE,gBAAgB,EACnE,wBAAwB,GAAG,yBAAyB,CACrD,CAAC;IACF,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AA0TD;;;;;GAKG;AACH,wBAAsB,6BAA6B,CAAC,IAAI,EAAE;IACxD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;CACpE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,QAAQ,EAAE,CAspB/E;AA+GD,KAAK,wBAAwB,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC"}
|
|
@@ -189,6 +189,50 @@ async function ingestPolledEvents(events, ingestFactoryEvent) {
|
|
|
189
189
|
const rejected = (await Promise.allSettled(events.map((event) => ingestFactoryEvent(event)))).find((result) => result.status === "rejected");
|
|
190
190
|
if (rejected) console.warn("[Mastra Factory] Failed to ingest polled GitHub events", { error: rejected.reason });
|
|
191
191
|
}
|
|
192
|
+
const POLLED_PAGE_INGEST_REST_MS = 2e4;
|
|
193
|
+
const POLLED_PAGE_INGEST_WAIT_MS = 1e4;
|
|
194
|
+
const POLLED_PAGE_INGEST_ABANDON_MS = 12e4;
|
|
195
|
+
function waitAtMost(pass) {
|
|
196
|
+
let timer;
|
|
197
|
+
const waited = new Promise((resolve) => {
|
|
198
|
+
timer = setTimeout(resolve, POLLED_PAGE_INGEST_WAIT_MS);
|
|
199
|
+
});
|
|
200
|
+
return Promise.race([pass, waited]).finally(() => clearTimeout(timer));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* One rules pass per listed page at a time, whichever board asked, then a rest: each pass reads the
|
|
204
|
+
* whole project, and every open board polls the same pages. A board joins a running pass unless it
|
|
205
|
+
* looks stuck, and a resting page still ingests the pull requests its last pass did not list.
|
|
206
|
+
*/
|
|
207
|
+
function createPolledPageIngest() {
|
|
208
|
+
const running = /* @__PURE__ */ new Map();
|
|
209
|
+
const resting = /* @__PURE__ */ new Map();
|
|
210
|
+
return (key, pullRequests, ingest) => {
|
|
211
|
+
const pending = running.get(key);
|
|
212
|
+
if (pending && Date.now() - pending.startedAt < POLLED_PAGE_INGEST_ABANDON_MS) return waitAtMost(pending.done);
|
|
213
|
+
for (const [rested, { finishedAt }] of resting) {
|
|
214
|
+
if (Date.now() - finishedAt < POLLED_PAGE_INGEST_REST_MS) break;
|
|
215
|
+
resting.delete(rested);
|
|
216
|
+
}
|
|
217
|
+
const rest = resting.get(key);
|
|
218
|
+
const due = rest ? pullRequests.filter((pullRequest) => !rest.ingested.has(pullRequest.number)) : pullRequests;
|
|
219
|
+
if (due.length === 0) return Promise.resolve();
|
|
220
|
+
const done = ingest(due).finally(() => {
|
|
221
|
+
if (running.get(key)?.done !== done) return;
|
|
222
|
+
running.delete(key);
|
|
223
|
+
if (rest) for (const pullRequest of due) rest.ingested.add(pullRequest.number);
|
|
224
|
+
else resting.set(key, {
|
|
225
|
+
finishedAt: Date.now(),
|
|
226
|
+
ingested: new Set(due.map((pullRequest) => pullRequest.number))
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
running.set(key, {
|
|
230
|
+
startedAt: Date.now(),
|
|
231
|
+
done
|
|
232
|
+
});
|
|
233
|
+
return waitAtMost(done);
|
|
234
|
+
};
|
|
235
|
+
}
|
|
192
236
|
const LINKED_BACKLOG_MAX_PAGES = 5;
|
|
193
237
|
function listedIssueOf(issue) {
|
|
194
238
|
return {
|
|
@@ -265,6 +309,7 @@ function buildGithubRoutes(options) {
|
|
|
265
309
|
stateSigner,
|
|
266
310
|
sandbox
|
|
267
311
|
});
|
|
312
|
+
const ingestPolledPage = createPolledPageIngest();
|
|
268
313
|
routes.push(registerApiRoute("/web/github/status", {
|
|
269
314
|
method: "GET",
|
|
270
315
|
requiresAuth: false,
|
|
@@ -597,7 +642,7 @@ function buildGithubRoutes(options) {
|
|
|
597
642
|
createdAt: pr.createdAt,
|
|
598
643
|
updatedAt: pr.updatedAt
|
|
599
644
|
}));
|
|
600
|
-
await ingestPolledEvents(
|
|
645
|
+
await ingestPolledPage(`${loaded.project.installation.externalId}:${loaded.project.repository.externalId}:${page}`, responsePullRequests, (listed) => ingestPolledEvents(listed.map((pullRequest) => listedPullRequestEvent(loaded.project, pullRequest)), options.ingestFactoryEvent));
|
|
601
646
|
return c.json({
|
|
602
647
|
pullRequests: responsePullRequests,
|
|
603
648
|
nextPage: nextCursor === null ? null : Number(nextCursor)
|