@mastra/factory 0.28.0-alpha.6 → 0.28.0-alpha.7

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.
Files changed (119) hide show
  1. package/dist/boards/board-writes.d.ts +1 -1
  2. package/dist/boards/board-writes.d.ts.map +1 -1
  3. package/dist/boards/board-writes.js +1 -1
  4. package/dist/boards/board-writes.js.map +1 -1
  5. package/dist/environment/build-runner.d.ts.map +1 -1
  6. package/dist/environment/build-runner.js +2 -2
  7. package/dist/environment/build-runner.js.map +1 -1
  8. package/dist/environment/build-workflow.d.ts.map +1 -1
  9. package/dist/environment/build-workflow.js +6 -5
  10. package/dist/environment/build-workflow.js.map +1 -1
  11. package/dist/environment/build.d.ts +15 -2
  12. package/dist/environment/build.d.ts.map +1 -1
  13. package/dist/environment/build.js +32 -9
  14. package/dist/environment/build.js.map +1 -1
  15. package/dist/factory.d.ts.map +1 -1
  16. package/dist/factory.js +29 -3
  17. package/dist/factory.js.map +1 -1
  18. package/dist/integrations/github/integration.d.ts.map +1 -1
  19. package/dist/integrations/github/integration.js +7 -3
  20. package/dist/integrations/github/integration.js.map +1 -1
  21. package/dist/integrations/github/issue-reconciler.js +2 -2
  22. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  23. package/dist/integrations/github/provenance.js +1 -1
  24. package/dist/integrations/github/provenance.js.map +1 -1
  25. package/dist/integrations/github/reconcile-worker.d.ts +5 -1
  26. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  27. package/dist/integrations/github/reconcile-worker.js +39 -6
  28. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  29. package/dist/integrations/github/routes.d.ts +4 -3
  30. package/dist/integrations/github/routes.d.ts.map +1 -1
  31. package/dist/integrations/github/routes.js +9 -86
  32. package/dist/integrations/github/routes.js.map +1 -1
  33. package/dist/integrations/github/rules.d.ts +67 -0
  34. package/dist/integrations/github/rules.d.ts.map +1 -1
  35. package/dist/integrations/github/rules.js +215 -12
  36. package/dist/integrations/github/rules.js.map +1 -1
  37. package/dist/integrations/github/sandbox.d.ts +10 -2
  38. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  39. package/dist/integrations/github/sandbox.js +20 -4
  40. package/dist/integrations/github/sandbox.js.map +1 -1
  41. package/dist/integrations/gitlab/merge-request-reconciler.js +1 -1
  42. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  43. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  44. package/dist/integrations/gitlab/rules.js +6 -5
  45. package/dist/integrations/gitlab/rules.js.map +1 -1
  46. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  47. package/dist/integrations/incidentio/rules.js +5 -2
  48. package/dist/integrations/incidentio/rules.js.map +1 -1
  49. package/dist/integrations/issue-reconciler.js +1 -1
  50. package/dist/integrations/issue-reconciler.js.map +1 -1
  51. package/dist/integrations/jira/rules.d.ts.map +1 -1
  52. package/dist/integrations/jira/rules.js +5 -2
  53. package/dist/integrations/jira/rules.js.map +1 -1
  54. package/dist/integrations/linear/rules.d.ts.map +1 -1
  55. package/dist/integrations/linear/rules.js +2 -2
  56. package/dist/integrations/linear/rules.js.map +1 -1
  57. package/dist/integrations/platform/github/event-worker.d.ts +4 -1
  58. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  59. package/dist/integrations/platform/github/event-worker.js +39 -3
  60. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  61. package/dist/integrations/platform/github/integration.d.ts +8 -0
  62. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  63. package/dist/integrations/platform/github/integration.js +21 -3
  64. package/dist/integrations/platform/github/integration.js.map +1 -1
  65. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  66. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  67. package/dist/integrations/platform/linear/event-worker.js +1 -1
  68. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  69. package/dist/mcp/routes.js +1 -1
  70. package/dist/mcp/routes.js.map +1 -1
  71. package/dist/routes/attention-parked.js +1 -1
  72. package/dist/routes/attention-parked.js.map +1 -1
  73. package/dist/routes/boards.d.ts +1 -1
  74. package/dist/routes/boards.d.ts.map +1 -1
  75. package/dist/routes/boards.js.map +1 -1
  76. package/dist/routes/contracts.d.ts +115 -0
  77. package/dist/routes/contracts.d.ts.map +1 -1
  78. package/dist/routes/contracts.js +69 -1
  79. package/dist/routes/contracts.js.map +1 -1
  80. package/dist/routes/projects.d.ts.map +1 -1
  81. package/dist/routes/projects.js +12 -6
  82. package/dist/routes/projects.js.map +1 -1
  83. package/dist/routes/sandbox-envs.d.ts +26 -0
  84. package/dist/routes/sandbox-envs.d.ts.map +1 -0
  85. package/dist/routes/sandbox-envs.js +180 -0
  86. package/dist/routes/sandbox-envs.js.map +1 -0
  87. package/dist/routes/work-items.js +1 -1
  88. package/dist/routes/work-items.js.map +1 -1
  89. package/dist/rules/dispatcher.d.ts.map +1 -1
  90. package/dist/rules/dispatcher.js +3 -2
  91. package/dist/rules/dispatcher.js.map +1 -1
  92. package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
  93. package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
  94. package/dist/sandbox/sandbox-env-cache.js +140 -0
  95. package/dist/sandbox/sandbox-env-cache.js.map +1 -0
  96. package/dist/sandbox/sandbox-env.d.ts +77 -0
  97. package/dist/sandbox/sandbox-env.d.ts.map +1 -0
  98. package/dist/sandbox/sandbox-env.js +130 -0
  99. package/dist/sandbox/sandbox-env.js.map +1 -0
  100. package/dist/storage/domains/audit/actions.d.ts +1 -0
  101. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  102. package/dist/storage/domains/audit/actions.js +5 -0
  103. package/dist/storage/domains/audit/actions.js.map +1 -1
  104. package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
  105. package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
  106. package/dist/storage/domains/sandbox-envs/base.js +227 -0
  107. package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
  108. package/dist/storage/domains/work-items/base.d.ts +2 -1
  109. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  110. package/dist/storage/domains/work-items/base.js +11 -2
  111. package/dist/storage/domains/work-items/base.js.map +1 -1
  112. package/dist/storage/domains/work-items/metrics.d.ts +1 -1
  113. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  114. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  115. package/dist/workspace.d.ts +3 -0
  116. package/dist/workspace.d.ts.map +1 -1
  117. package/dist/workspace.js +21 -4
  118. package/dist/workspace.js.map +1 -1
  119. package/package.json +6 -6
@@ -1,6 +1,7 @@
1
1
  import type { BoardEventFacts } from '../../boards/board-events.js';
2
2
  import type { BoardRegistry } from '../../boards/index.js';
3
3
  import type { ProjectBoardSource } from '../../boards/project-boards.js';
4
+ import type { PullRequest, VersionControl } from '../../capabilities/version-control.js';
4
5
  import type { FactoryGithubRuleContext, FactorySignalActivityDecision } from '../../rules/types.js';
5
6
  import type { StoredBoardScope } from '../../storage/domains/boards/base.js';
6
7
  import type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';
@@ -92,6 +93,9 @@ export interface ReconcilePullRequestState {
92
93
  }
93
94
  export interface PolledPullRequestState extends ReconcilePullRequestState {
94
95
  createdAt: string;
96
+ /** Carried so a replayed opening records the head it opens with, as the webhook does. */
97
+ headSha?: string;
98
+ updatedAt?: string;
95
99
  }
96
100
  export type GithubPullRequestFetcher = (input: {
97
101
  installationId: number;
@@ -122,6 +126,27 @@ export type GithubOpenIssueLister = (input: {
122
126
  }) => Promise<Array<ReconcileIssueState & {
123
127
  number: number;
124
128
  }>>;
129
+ /**
130
+ * Lists a repository's open, non-draft pull requests opened at or after
131
+ * `createdSince` (epoch ms) for missed-open discovery.
132
+ */
133
+ export type GithubOpenPullRequestLister = (input: {
134
+ installationId: number;
135
+ repository: string;
136
+ createdSince: number;
137
+ }) => Promise<Array<PolledPullRequestState & {
138
+ number: number;
139
+ }>>;
140
+ /** The facts of an open, non-draft pull request as a version-control listing reports them. */
141
+ export declare function listedPullRequestState(pullRequest: PullRequest): PolledPullRequestState & {
142
+ number: number;
143
+ };
144
+ /**
145
+ * Missed-open discovery over an integration's version-control capability.
146
+ * GitHub lists open pull requests newest first, so paging stops at the first
147
+ * page opened entirely before `createdSince`, or at the page cap.
148
+ */
149
+ export declare function openPullRequestLister(versionControl: Pick<VersionControl, 'listPullRequests'>): GithubOpenPullRequestLister;
125
150
  export interface ReconcileRepository {
126
151
  id: number;
127
152
  fullName: string;
@@ -147,6 +172,25 @@ export interface ReconcileSweepSummary {
147
172
  }>;
148
173
  }
149
174
  export type GithubPullRequestReconciler = (repositories: ReconcileRepository[]) => Promise<ReconcileSweepSummary>;
175
+ export interface GithubPullRequestDiscoverySummary {
176
+ /** Factory-configured repositories included in the sweep. */
177
+ repositories: number;
178
+ /** Open pull requests listed, opened since their repository was linked. */
179
+ listed: number;
180
+ /** Open pull requests with no card, replayed as missed opens. */
181
+ created: number;
182
+ /** Open pull requests whose authoring card had lost its open mark, restored by replaying the opening. */
183
+ repaired: number;
184
+ /** Repositories or pull requests skipped because of an error. */
185
+ failed: number;
186
+ /** Error samples with context, capped at {@link RECONCILE_ERROR_SAMPLE_LIMIT}. */
187
+ errors: Array<{
188
+ repository: string;
189
+ pullRequestNumber?: number;
190
+ error: string;
191
+ }>;
192
+ }
193
+ export type GithubPullRequestDiscovery = (repositories: ReconcileRepository[]) => Promise<GithubPullRequestDiscoverySummary>;
150
194
  export declare const RECONCILE_ERROR_SAMPLE_LIMIT = 5;
151
195
  export declare function sameStrings(left: unknown, right: string[] | undefined): boolean;
152
196
  /**
@@ -176,14 +220,37 @@ export declare function reconciledIssueRelabeledEvent(repository: ReconcileRepos
176
220
  */
177
221
  export declare function reconciledIssueOpenedEvent(repository: ReconcileRepository, issueNumber: number, state: ReconcileIssueState): ParsedGithubWebhook;
178
222
  export declare function polledPullRequestEvent(repository: ReconcileRepository, pullRequestNumber: number, state: PolledPullRequestState): ParsedGithubWebhook;
223
+ /**
224
+ * Replays an open pull request that has no card as the `opened` delivery
225
+ * GitHub never sent. The delivery id is stable per pull request so repeat
226
+ * sweeps dedupe at the ingress.
227
+ */
228
+ export declare function reconciledPullRequestOpenedEvent(repository: ReconcileRepository, pullRequestNumber: number, state: PolledPullRequestState): ParsedGithubWebhook;
179
229
  export declare function reconciledClosedEvent(repository: ReconcileRepository, pullRequestNumber: number, state: ReconcilePullRequestState): ParsedGithubWebhook;
180
230
  /**
181
231
  * State-based safety net for merge signals: webhooks and event-log tailing
182
232
  * can miss a merge (cursor gaps, downtime, terminally failed decisions), so
183
233
  * this sweep compares still-open PR cards against actual GitHub state and
184
234
  * replays the merge through the normal rules ingress when they disagree.
235
+ * Missed opens are {@link createGithubPullRequestDiscovery}'s, on its own cadence.
185
236
  */
186
237
  export declare function createGithubPullRequestReconciler(options: GithubRulesOptions, fetchPullRequest: GithubPullRequestFetcher): GithubPullRequestReconciler;
238
+ /** A non-terminal card that holds an open pull request but no longer records it as the one it has out. */
239
+ /**
240
+ * Catches what the opened webhook (or its follow-up writes) missed, from the
241
+ * open pull request list alone, so its GitHub cost is the listing's and does
242
+ * not grow with the cards on the board:
243
+ *
244
+ * - an open pull request filed since the repository was linked that no card
245
+ * holds is replayed as its `opened` delivery, which files it;
246
+ * - an open pull request whose authoring card lost its open mark (the write
247
+ * after the opening failed) is replayed the same way, which restores it.
248
+ *
249
+ * Both replays use one stable delivery id per pull request, so repeats in
250
+ * later sweeps are absorbed by the ingress instead of filing a second card.
251
+ */
252
+ export declare function createGithubPullRequestDiscovery(options: GithubRulesOptions, listOpenPullRequests: GithubOpenPullRequestLister): GithubPullRequestDiscovery;
253
+ export declare function attachGithubPullRequestDiscovery(github: GithubRulesIntegration, context: IntegrationContext, listOpenPullRequests: GithubOpenPullRequestLister): GithubPullRequestDiscovery | undefined;
187
254
  export declare function githubRulesOptions(github: GithubRulesIntegration, context: IntegrationContext): GithubRulesOptions | undefined;
188
255
  export declare function attachGithubRules(github: GithubRulesIntegration, context: IntegrationContext): ((event: ParsedGithubWebhook) => Promise<unknown>) | undefined;
189
256
  export declare function attachGithubReconciler(github: GithubRulesIntegration, context: IntegrationContext, fetchPullRequest: GithubPullRequestFetcher): GithubPullRequestReconciler | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/rules.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAgBpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAIzE,OAAO,KAAK,EAEV,wBAAwB,EAIxB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAM/G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AAE9F,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AA+ExD;;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 +771,12 @@ var GithubRules = class {
771
771
  factoryProjectId: projectId,
772
772
  sources: githubItemSources(repositoryId, "pull-request", pullRequestNumber)
773
773
  });
774
- const items = await this.options.storage.list({
774
+ const items = await this.options.storage.listShared({
775
775
  orgId,
776
776
  factoryProjectId: projectId
777
777
  });
778
778
  const linked = resolved.externalSource?.type === "pull-request" ? resolved.parentWorkItemId ? await this.#parentItem(orgId, projectId, items, resolved) : branchAuthoringItem(items, headBranch, repositoryId, repositoryFullName) : items.find((item) => item.parentWorkItemId === resolved.id && (item.externalSource?.externalId === canonicalSourceKey("pull-request", pullRequestNumber) || item.externalSource?.externalId === legacySourceKey(repositoryId, "pull-request", pullRequestNumber)) && cardBelongsToRepository(item, repositoryId, repositoryFullName));
779
- return linked?.id === resolved.id ? void 0 : linked;
779
+ return linked && linked.id !== resolved.id ? structuredClone(linked) : void 0;
780
780
  }
781
781
  /**
782
782
  * The existing card a pull request opened for the first time belongs with, or undefined when it
@@ -789,7 +789,7 @@ var GithubRules = class {
789
789
  */
790
790
  async #pullRequestHome(input) {
791
791
  if (!input.factoryAuthored && !input.authorTrusted) return void 0;
792
- const items = await this.options.storage.list({
792
+ const items = await this.options.storage.listShared({
793
793
  orgId: input.orgId,
794
794
  factoryProjectId: input.factoryProjectId
795
795
  });
@@ -806,7 +806,7 @@ var GithubRules = class {
806
806
  })) {
807
807
  const card = items.find((item) => (item.externalSource?.externalId === canonicalSourceKey("issue", issueNumber) || item.externalSource?.externalId === legacySourceKey(input.repositoryId, "issue", issueNumber)) && eligible(item));
808
808
  if (card) return {
809
- card,
809
+ card: structuredClone(card),
810
810
  reason: "closes"
811
811
  };
812
812
  }
@@ -818,13 +818,13 @@ var GithubRules = class {
818
818
  sources: [...issueNumber ? githubItemSources(repositoryId, "issue", issueNumber) : [], ...pullRequestNumber ? githubItemSources(repositoryId, "pull-request", pullRequestNumber) : []]
819
819
  });
820
820
  if (provenance) await this.options.storage.getForProject(orgId, projectId, provenance.workItemId);
821
- const items = await this.options.storage.list({
821
+ const items = await this.options.storage.listShared({
822
822
  orgId,
823
823
  factoryProjectId: projectId
824
824
  });
825
825
  const resolved = this.#resolveItem(items, repositoryId, repositoryFullName, issueNumber, pullRequestNumber, pullRequestHeadBranch, provenance);
826
- if (preferAuthoringItem && resolved?.externalSource?.type === "pull-request" && resolved.parentWorkItemId) return await this.#parentItem(orgId, projectId, items, resolved) ?? resolved;
827
- return resolved;
826
+ if (preferAuthoringItem && resolved?.externalSource?.type === "pull-request" && resolved.parentWorkItemId) return structuredClone(await this.#parentItem(orgId, projectId, items, resolved) ?? resolved);
827
+ return resolved && structuredClone(resolved);
828
828
  }
829
829
  /** The card `child` was filed from; read on its own when the board list lacks it (not copied yet). */
830
830
  async #parentItem(orgId, projectId, items, child) {
@@ -837,6 +837,61 @@ var GithubRules = class {
837
837
  if (pullRequestNumber) return items.find((item) => item.externalSource?.externalId === canonicalSourceKey("pull-request", pullRequestNumber) && cardBelongsToRepository(item, repositoryId, repositoryFullName)) ?? items.find((item) => item.externalSource?.externalId === legacySourceKey(repositoryId, "pull-request", pullRequestNumber)) ?? items.find((item) => attachedPullRequestSource(item, repositoryId, repositoryFullName, pullRequestNumber)) ?? branchAuthoringItem(items, pullRequestHeadBranch, repositoryId, repositoryFullName);
838
838
  }
839
839
  };
840
+ /** The facts of an open, non-draft pull request as a version-control listing reports them. */
841
+ function listedPullRequestState(pullRequest) {
842
+ return {
843
+ number: Number(pullRequest.id),
844
+ title: pullRequest.title,
845
+ url: pullRequest.url,
846
+ state: "open",
847
+ draft: false,
848
+ merged: false,
849
+ assignees: pullRequest.assignees ?? [],
850
+ requestedReviewers: pullRequest.requestedReviewers ?? [],
851
+ labels: pullRequest.labels ?? [],
852
+ headBranch: pullRequest.headBranch,
853
+ baseBranch: pullRequest.baseBranch,
854
+ ...pullRequest.author ? { author: pullRequest.author } : {},
855
+ createdAt: pullRequest.createdAt,
856
+ headSha: pullRequest.headSha,
857
+ updatedAt: pullRequest.updatedAt
858
+ };
859
+ }
860
+ /**
861
+ * Missed-open discovery reads at most this many pages per repository per sweep,
862
+ * so a repository flooded with pull requests (or a listing whose cursor never
863
+ * ends) cannot grow a sweep's API cost without limit. A missed open is among
864
+ * the newest, and thirty per page keeps the 600 newest in reach.
865
+ */
866
+ const OPEN_PULL_REQUEST_DISCOVERY_MAX_PAGES = 20;
867
+ /**
868
+ * Missed-open discovery over an integration's version-control capability.
869
+ * GitHub lists open pull requests newest first, so paging stops at the first
870
+ * page opened entirely before `createdSince`, or at the page cap.
871
+ */
872
+ function openPullRequestLister(versionControl) {
873
+ return async ({ installationId, repository, createdSince }) => {
874
+ const states = [];
875
+ let cursor = "1";
876
+ for (let page = 0; cursor !== null && page < OPEN_PULL_REQUEST_DISCOVERY_MAX_PAGES; page += 1) {
877
+ const listed = await versionControl.listPullRequests({
878
+ connection: {
879
+ type: "app-installation",
880
+ installationId
881
+ },
882
+ sourceId: repository,
883
+ state: "open",
884
+ includeDrafts: true,
885
+ cursor
886
+ });
887
+ const recent = listed.pullRequests.filter((pullRequest) => !(Date.parse(pullRequest.createdAt) < createdSince));
888
+ states.push(...recent.filter((pullRequest) => !pullRequest.draft).map(listedPullRequestState));
889
+ if (recent.length === 0) break;
890
+ cursor = listed.nextCursor;
891
+ }
892
+ return states;
893
+ };
894
+ }
840
895
  const RECONCILE_ERROR_SAMPLE_LIMIT = 5;
841
896
  function sameStrings(left, right) {
842
897
  if (right === void 0) return true;
@@ -989,6 +1044,17 @@ function polledPullRequestEvent(repository, pullRequestNumber, state) {
989
1044
  }
990
1045
  };
991
1046
  }
1047
+ /**
1048
+ * Replays an open pull request that has no card as the `opened` delivery
1049
+ * GitHub never sent. The delivery id is stable per pull request so repeat
1050
+ * sweeps dedupe at the ingress.
1051
+ */
1052
+ function reconciledPullRequestOpenedEvent(repository, pullRequestNumber, state) {
1053
+ return {
1054
+ ...polledPullRequestEvent(repository, pullRequestNumber, state),
1055
+ deliveryId: `reconcile:${repository.id}:pull-request:${pullRequestNumber}:opened`
1056
+ };
1057
+ }
992
1058
  function reconciledClosedEvent(repository, pullRequestNumber, state) {
993
1059
  const outcome = state.merged ? "merged" : "closed";
994
1060
  return {
@@ -1020,10 +1086,14 @@ function pullRequestPayload(pullRequestNumber, state) {
1020
1086
  assignees: githubUsers(state.assignees),
1021
1087
  requested_reviewers: githubUsers(state.requestedReviewers),
1022
1088
  labels: githubLabels(state.labels),
1023
- head: { ref: state.headBranch },
1089
+ head: {
1090
+ ref: state.headBranch,
1091
+ ...state.headSha ? { sha: state.headSha } : {}
1092
+ },
1024
1093
  base: { ref: state.baseBranch }
1025
1094
  };
1026
1095
  if (state.createdAt) payload.created_at = state.createdAt;
1096
+ if (state.updatedAt) payload.updated_at = state.updatedAt;
1027
1097
  if (state.author) payload.user = { login: state.author };
1028
1098
  return payload;
1029
1099
  }
@@ -1069,6 +1139,7 @@ async function retireReconciledSubscriptions(storage, repository, pullRequestNum
1069
1139
  * can miss a merge (cursor gaps, downtime, terminally failed decisions), so
1070
1140
  * this sweep compares still-open PR cards against actual GitHub state and
1071
1141
  * replays the merge through the normal rules ingress when they disagree.
1142
+ * Missed opens are {@link createGithubPullRequestDiscovery}'s, on its own cadence.
1072
1143
  */
1073
1144
  function createGithubPullRequestReconciler(options, fetchPullRequest) {
1074
1145
  const rules = new GithubRules(options);
@@ -1089,8 +1160,7 @@ function createGithubPullRequestReconciler(options, fetchPullRequest) {
1089
1160
  error: error instanceof Error ? error.message : String(error)
1090
1161
  });
1091
1162
  };
1092
- const configured = new Set((await options.sourceControl.projectRepositories.listConfiguredExternalKeys()).map((key) => `${key.installationExternalId}\u0000${key.repositoryExternalId}`));
1093
- const scoped = repositories.filter((repository) => configured.has(`${repository.installationId}\u0000${repository.id}`));
1163
+ const scoped = await linkedRepositories(options, repositories);
1094
1164
  summary.repositories = scoped.length;
1095
1165
  for (const repository of scoped) {
1096
1166
  let cardsByNumber;
@@ -1107,7 +1177,7 @@ function createGithubPullRequestReconciler(options, fetchPullRequest) {
1107
1177
  unanswered = [];
1108
1178
  for (const project of projects) {
1109
1179
  await rules.loadBoards(project);
1110
- const items = await options.storage.list({
1180
+ const items = await options.storage.listShared({
1111
1181
  orgId: project.orgId,
1112
1182
  factoryProjectId: project.factoryProjectId
1113
1183
  });
@@ -1249,6 +1319,139 @@ function createGithubPullRequestReconciler(options, fetchPullRequest) {
1249
1319
  return summary;
1250
1320
  };
1251
1321
  }
1322
+ /**
1323
+ * An installation can expose hundreds of repositories; only the ones actually
1324
+ * linked to a factory project can have cards, so sweeps scope to those up
1325
+ * front instead of probing each repository.
1326
+ */
1327
+ async function linkedRepositories(options, repositories) {
1328
+ const configured = new Set((await options.sourceControl.projectRepositories.listConfiguredExternalKeys()).map((key) => `${key.installationExternalId}\u0000${key.repositoryExternalId}`));
1329
+ return repositories.filter((repository) => configured.has(`${repository.installationId}\u0000${repository.id}`));
1330
+ }
1331
+ /** A non-terminal card that holds an open pull request but no longer records it as the one it has out. */
1332
+ /**
1333
+ * Catches what the opened webhook (or its follow-up writes) missed, from the
1334
+ * open pull request list alone, so its GitHub cost is the listing's and does
1335
+ * not grow with the cards on the board:
1336
+ *
1337
+ * - an open pull request filed since the repository was linked that no card
1338
+ * holds is replayed as its `opened` delivery, which files it;
1339
+ * - an open pull request whose authoring card lost its open mark (the write
1340
+ * after the opening failed) is replayed the same way, which restores it.
1341
+ *
1342
+ * Both replays use one stable delivery id per pull request, so repeats in
1343
+ * later sweeps are absorbed by the ingress instead of filing a second card.
1344
+ */
1345
+ function createGithubPullRequestDiscovery(options, listOpenPullRequests) {
1346
+ const rules = new GithubRules(options);
1347
+ const boards = toBoardSource(options.boards);
1348
+ return async (repositories) => {
1349
+ const summary = {
1350
+ repositories: 0,
1351
+ listed: 0,
1352
+ created: 0,
1353
+ repaired: 0,
1354
+ failed: 0,
1355
+ errors: []
1356
+ };
1357
+ const recordFailure = (repository, error, pullRequestNumber) => {
1358
+ summary.failed += 1;
1359
+ if (summary.errors.length < 5) summary.errors.push({
1360
+ repository: repository.fullName,
1361
+ ...pullRequestNumber === void 0 ? {} : { pullRequestNumber },
1362
+ error: error instanceof Error ? error.message : String(error)
1363
+ });
1364
+ };
1365
+ const scoped = await linkedRepositories(options, repositories);
1366
+ summary.repositories = scoped.length;
1367
+ for (const repository of scoped) {
1368
+ const carded = /* @__PURE__ */ new Set();
1369
+ const unmarked = /* @__PURE__ */ new Map();
1370
+ let linkedAt;
1371
+ try {
1372
+ const projects = await options.sourceControl.projectRepositories.listByExternalRepository({
1373
+ installationExternalId: String(repository.installationId),
1374
+ repositoryExternalId: String(repository.id)
1375
+ });
1376
+ if (projects.length === 0) continue;
1377
+ linkedAt = Math.min(...projects.map((project) => project.projectRepository.createdAt.getTime()));
1378
+ const items = [];
1379
+ for (const project of projects) {
1380
+ await rules.loadBoards(project);
1381
+ items.push(...await options.storage.listShared({
1382
+ orgId: project.orgId,
1383
+ factoryProjectId: project.factoryProjectId
1384
+ }));
1385
+ }
1386
+ const authoring = (item) => item !== void 0 && item.externalSource?.type !== "pull-request" && typeof item.metadata?.openPullRequestNumber !== "number" && !isTerminalWorkItem(boards.forProject(item), item);
1387
+ const byId = new Map(items.map((item) => [item.id, item]));
1388
+ for (const item of items) {
1389
+ for (const source of pullRequestSources(item)) {
1390
+ const number = attachedPullRequestNumber(source, repository);
1391
+ if (number === void 0) continue;
1392
+ carded.add(number);
1393
+ if (authoring(item) && !["closed", "merged"].includes(source.state ?? "")) unmarked.set(number, [...unmarked.get(number) ?? [], item]);
1394
+ }
1395
+ const number = reconcilablePullRequestNumber(item, repository);
1396
+ if (number === void 0) continue;
1397
+ carded.add(number);
1398
+ const parent = item.parentWorkItemId ? byId.get(item.parentWorkItemId) : void 0;
1399
+ if (parent && authoring(parent) && !["closed", "merged"].includes(item.workItem.state ?? "")) unmarked.set(number, [...unmarked.get(number) ?? [], parent]);
1400
+ }
1401
+ } catch (error) {
1402
+ recordFailure(repository, error);
1403
+ continue;
1404
+ }
1405
+ let open;
1406
+ try {
1407
+ open = await listOpenPullRequests({
1408
+ installationId: repository.installationId,
1409
+ repository: repository.fullName,
1410
+ createdSince: linkedAt
1411
+ });
1412
+ } catch (error) {
1413
+ recordFailure(repository, error);
1414
+ continue;
1415
+ }
1416
+ summary.listed += open.length;
1417
+ const restored = /* @__PURE__ */ new Set();
1418
+ for (const pullRequest of open) try {
1419
+ if (!carded.has(pullRequest.number)) {
1420
+ if ((await rules.ingest(reconciledPullRequestOpenedEvent(repository, pullRequest.number, pullRequest))).status === "committed") summary.created += 1;
1421
+ continue;
1422
+ }
1423
+ const candidate = await ownedUnmarkedCard(options, repository, pullRequest, (unmarked.get(pullRequest.number) ?? []).filter((card) => !restored.has(card.id)));
1424
+ if (!candidate) continue;
1425
+ restored.add(candidate.id);
1426
+ await rules.ingest(reconciledPullRequestOpenedEvent(repository, pullRequest.number, pullRequest));
1427
+ if ((await options.storage.get({
1428
+ orgId: candidate.orgId,
1429
+ id: candidate.id
1430
+ }))?.metadata?.openPullRequestNumber === pullRequest.number) summary.repaired += 1;
1431
+ } catch (error) {
1432
+ recordFailure(repository, error, pullRequest.number);
1433
+ }
1434
+ }
1435
+ return summary;
1436
+ };
1437
+ }
1438
+ /**
1439
+ * The unmarked card an open pull request's replayed opening would mark: the
1440
+ * one Factory's provenance names, which is the only link a replay resolves
1441
+ * back to the authoring card once the pull request has its own Review card.
1442
+ * Decided from storage, so a card holding someone else's pull request (or one
1443
+ * a replay cannot restore) costs no replay, and no permission lookup, per sweep.
1444
+ */
1445
+ async function ownedUnmarkedCard(options, repository, pullRequest, candidates) {
1446
+ if (candidates.length === 0) return void 0;
1447
+ const provenance = await options.integrationStorage.subscriptions.listByTarget(provenanceTarget(repository.id, pullRequest.number), { status: "active" });
1448
+ return candidates.find((card) => provenance.some((subscription) => subscription.orgId === card.orgId && pullRequestProvenance(subscription.data, card.factoryProjectId)?.workItemId === card.id));
1449
+ }
1450
+ function attachGithubPullRequestDiscovery(github, context, listOpenPullRequests) {
1451
+ const options = githubRulesOptions(github, context);
1452
+ if (!options) return void 0;
1453
+ return createGithubPullRequestDiscovery(options, listOpenPullRequests);
1454
+ }
1252
1455
  function githubRulesOptions(github, context) {
1253
1456
  if (!context.runtime) return void 0;
1254
1457
  return {
@@ -1273,6 +1476,6 @@ function attachGithubReconciler(github, context, fetchPullRequest) {
1273
1476
  if (!options) return void 0;
1274
1477
  return createGithubPullRequestReconciler(options, fetchPullRequest);
1275
1478
  }
1276
- export { GithubRules, RECONCILE_ERROR_SAMPLE_LIMIT, activitySignalFor, attachGithubReconciler, attachGithubRules, attachedPullRequestSource, boardEventFor, cardBelongsToRepository, createGithubPullRequestReconciler, githubItemSources, githubRulesOptions, isFactoryGithubLogin, polledPullRequestEvent, reconcilableIssueNumber, reconciledClosedEvent, reconciledIssueClosedEvent, reconciledIssueOpenedEvent, reconciledIssueRelabeledEvent, sameStrings, sweepTrustLookup, trustedCollaborator };
1479
+ export { GithubRules, RECONCILE_ERROR_SAMPLE_LIMIT, activitySignalFor, attachGithubPullRequestDiscovery, attachGithubReconciler, attachGithubRules, attachedPullRequestSource, boardEventFor, cardBelongsToRepository, createGithubPullRequestDiscovery, createGithubPullRequestReconciler, githubItemSources, githubRulesOptions, isFactoryGithubLogin, listedPullRequestState, openPullRequestLister, polledPullRequestEvent, reconcilableIssueNumber, reconciledClosedEvent, reconciledIssueClosedEvent, reconciledIssueOpenedEvent, reconciledIssueRelabeledEvent, reconciledPullRequestOpenedEvent, sameStrings, sweepTrustLookup, trustedCollaborator };
1277
1480
 
1278
1481
  //# sourceMappingURL=rules.js.map