@oss-autopilot/core 3.42.5 → 3.44.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.
Files changed (192) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +428 -27
  3. package/dist/cli.bundle.cjs +212 -156
  4. package/dist/commands/check-integration.js +5 -1
  5. package/dist/commands/cleanup.d.ts +80 -0
  6. package/dist/commands/cleanup.js +334 -0
  7. package/dist/commands/comments.d.ts +14 -1
  8. package/dist/commands/comments.js +17 -5
  9. package/dist/commands/config.d.ts +2 -0
  10. package/dist/commands/config.js +63 -6
  11. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  12. package/dist/commands/daily-dismiss-filter.js +17 -1
  13. package/dist/commands/daily-ledger.d.ts +150 -0
  14. package/dist/commands/daily-ledger.js +248 -0
  15. package/dist/commands/daily-recent-prs.d.ts +26 -0
  16. package/dist/commands/daily-recent-prs.js +55 -0
  17. package/dist/commands/daily-render.d.ts +2 -1
  18. package/dist/commands/daily-render.js +4 -1
  19. package/dist/commands/daily.d.ts +5 -1
  20. package/dist/commands/daily.js +83 -93
  21. package/dist/commands/dashboard-cache.d.ts +2 -0
  22. package/dist/commands/dashboard-cache.js +33 -8
  23. package/dist/commands/dashboard-data.js +113 -69
  24. package/dist/commands/dashboard-gist-sync.js +3 -1
  25. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  26. package/dist/commands/dashboard-lifecycle.js +132 -39
  27. package/dist/commands/dashboard-process.d.ts +49 -1
  28. package/dist/commands/dashboard-process.js +111 -12
  29. package/dist/commands/dashboard-server.js +89 -23
  30. package/dist/commands/detect-formatters.js +1 -0
  31. package/dist/commands/dismiss.js +11 -7
  32. package/dist/commands/doctor.d.ts +15 -1
  33. package/dist/commands/doctor.js +66 -5
  34. package/dist/commands/draft.d.ts +77 -0
  35. package/dist/commands/draft.js +218 -0
  36. package/dist/commands/eval.js +1 -0
  37. package/dist/commands/fork-prune.d.ts +58 -0
  38. package/dist/commands/fork-prune.js +247 -0
  39. package/dist/commands/guidelines.d.ts +69 -2
  40. package/dist/commands/guidelines.js +158 -14
  41. package/dist/commands/index.d.ts +29 -4
  42. package/dist/commands/index.js +20 -3
  43. package/dist/commands/issue-thread.d.ts +46 -0
  44. package/dist/commands/issue-thread.js +123 -0
  45. package/dist/commands/ledger-backfill.d.ts +9 -0
  46. package/dist/commands/ledger-backfill.js +44 -1
  47. package/dist/commands/list-mark-done.d.ts +2 -1
  48. package/dist/commands/list-mark-done.js +3 -1
  49. package/dist/commands/list-move-tier.d.ts +2 -1
  50. package/dist/commands/list-move-tier.js +3 -1
  51. package/dist/commands/local-repos.js +10 -5
  52. package/dist/commands/locate-issue-list.d.ts +40 -17
  53. package/dist/commands/locate-issue-list.js +148 -88
  54. package/dist/commands/move.js +7 -1
  55. package/dist/commands/overnight-handoff.d.ts +17 -7
  56. package/dist/commands/overnight-handoff.js +36 -14
  57. package/dist/commands/overnight-push-prep.d.ts +14 -8
  58. package/dist/commands/overnight-push-prep.js +107 -35
  59. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  60. package/dist/commands/overnight-tool-rules.js +217 -0
  61. package/dist/commands/overnight.d.ts +5 -6
  62. package/dist/commands/overnight.js +61 -140
  63. package/dist/commands/parse-list.js +7 -1
  64. package/dist/commands/policy.d.ts +90 -0
  65. package/dist/commands/policy.js +276 -0
  66. package/dist/commands/pr-create.d.ts +48 -0
  67. package/dist/commands/pr-create.js +200 -0
  68. package/dist/commands/pr-preflight.d.ts +69 -0
  69. package/dist/commands/pr-preflight.js +348 -0
  70. package/dist/commands/repo-vet.d.ts +9 -0
  71. package/dist/commands/repo-vet.js +36 -11
  72. package/dist/commands/scout-bridge.js +18 -8
  73. package/dist/commands/search.js +7 -0
  74. package/dist/commands/setup.d.ts +3 -3
  75. package/dist/commands/setup.js +160 -48
  76. package/dist/commands/skip-add.js +10 -1
  77. package/dist/commands/startup.d.ts +12 -3
  78. package/dist/commands/startup.js +82 -49
  79. package/dist/commands/state-cmd.d.ts +2 -0
  80. package/dist/commands/state-cmd.js +5 -1
  81. package/dist/commands/stats.js +1 -0
  82. package/dist/commands/status.js +6 -0
  83. package/dist/commands/strategy.js +1 -0
  84. package/dist/commands/validation.d.ts +5 -0
  85. package/dist/commands/validation.js +5 -0
  86. package/dist/commands/vet-list.d.ts +6 -0
  87. package/dist/commands/vet-list.js +26 -1
  88. package/dist/commands/vet.d.ts +20 -0
  89. package/dist/commands/vet.js +133 -2
  90. package/dist/commands/work.d.ts +4 -0
  91. package/dist/commands/work.js +34 -11
  92. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  93. package/dist/core/anti-llm-policy.d.ts +3 -0
  94. package/dist/core/anti-llm-policy.js +3 -0
  95. package/dist/core/auth.js +2 -0
  96. package/dist/core/ci-analysis.d.ts +7 -2
  97. package/dist/core/ci-analysis.js +76 -21
  98. package/dist/core/commit-date.d.ts +45 -0
  99. package/dist/core/commit-date.js +45 -0
  100. package/dist/core/compliance-score.d.ts +3 -0
  101. package/dist/core/compliance-score.js +13 -9
  102. package/dist/core/config-registry.d.ts +27 -2
  103. package/dist/core/config-registry.js +94 -7
  104. package/dist/core/contributing.d.ts +2 -3
  105. package/dist/core/contributing.js +2 -3
  106. package/dist/core/daily-logic.d.ts +30 -5
  107. package/dist/core/daily-logic.js +68 -19
  108. package/dist/core/errors.d.ts +37 -3
  109. package/dist/core/errors.js +54 -5
  110. package/dist/core/fork-prune.d.ts +149 -0
  111. package/dist/core/fork-prune.js +333 -0
  112. package/dist/core/gist-health.d.ts +15 -3
  113. package/dist/core/gist-health.js +8 -0
  114. package/dist/core/gist-state-store.d.ts +24 -4
  115. package/dist/core/gist-state-store.js +98 -51
  116. package/dist/core/github-stats.d.ts +110 -16
  117. package/dist/core/github-stats.js +295 -110
  118. package/dist/core/http-cache.d.ts +0 -10
  119. package/dist/core/http-cache.js +0 -19
  120. package/dist/core/index.d.ts +13 -6
  121. package/dist/core/index.js +16 -6
  122. package/dist/core/issue-conversation.d.ts +8 -2
  123. package/dist/core/issue-conversation.js +31 -12
  124. package/dist/core/local-config.d.ts +95 -0
  125. package/dist/core/local-config.js +270 -0
  126. package/dist/core/merged-pr-notes.d.ts +2 -2
  127. package/dist/core/pacing.d.ts +41 -0
  128. package/dist/core/pacing.js +115 -0
  129. package/dist/core/pagination.d.ts +55 -0
  130. package/dist/core/pagination.js +59 -0
  131. package/dist/core/paths.d.ts +7 -0
  132. package/dist/core/paths.js +9 -0
  133. package/dist/core/pr-assembly.d.ts +2 -0
  134. package/dist/core/pr-assembly.js +6 -2
  135. package/dist/core/pr-graphql.d.ts +53 -4
  136. package/dist/core/pr-graphql.js +87 -14
  137. package/dist/core/pr-monitor.d.ts +35 -12
  138. package/dist/core/pr-monitor.js +110 -26
  139. package/dist/core/pr-preflight.d.ts +154 -0
  140. package/dist/core/pr-preflight.js +753 -0
  141. package/dist/core/pr-quality-rubric.d.ts +0 -6
  142. package/dist/core/pr-quality-rubric.js +0 -8
  143. package/dist/core/pr-template.d.ts +2 -0
  144. package/dist/core/pr-template.js +5 -1
  145. package/dist/core/prose-script.d.ts +72 -0
  146. package/dist/core/prose-script.js +223 -0
  147. package/dist/core/repo-policy.d.ts +111 -0
  148. package/dist/core/repo-policy.js +428 -0
  149. package/dist/core/repo-score-manager.d.ts +66 -0
  150. package/dist/core/repo-score-manager.js +140 -1
  151. package/dist/core/review-analysis.d.ts +49 -21
  152. package/dist/core/review-analysis.js +89 -15
  153. package/dist/core/reviewed-prs-fetch.js +11 -29
  154. package/dist/core/reviewed-prs.js +8 -15
  155. package/dist/core/stale-data.d.ts +78 -0
  156. package/dist/core/stale-data.js +153 -0
  157. package/dist/core/state-persistence.d.ts +62 -27
  158. package/dist/core/state-persistence.js +338 -119
  159. package/dist/core/state-schema.d.ts +152 -210
  160. package/dist/core/state-schema.js +232 -80
  161. package/dist/core/state.d.ts +81 -8
  162. package/dist/core/state.js +239 -46
  163. package/dist/core/status-determination.js +32 -12
  164. package/dist/core/strategy.js +3 -1
  165. package/dist/core/types.d.ts +22 -1
  166. package/dist/core/types.js +1 -0
  167. package/dist/core/untrusted-content.d.ts +30 -11
  168. package/dist/core/untrusted-content.js +95 -42
  169. package/dist/core/urls.d.ts +33 -0
  170. package/dist/core/urls.js +94 -0
  171. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  172. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  173. package/dist/dashboard/index.html +1 -1
  174. package/dist/formatters/json.d.ts +432 -10
  175. package/dist/formatters/json.js +156 -1
  176. package/package.json +6 -6
  177. package/dist/core/ci-enforced-tools.d.ts +0 -35
  178. package/dist/core/ci-enforced-tools.js +0 -109
  179. package/dist/core/comment-decision.d.ts +0 -79
  180. package/dist/core/comment-decision.js +0 -82
  181. package/dist/core/extraction-categories.d.ts +0 -55
  182. package/dist/core/extraction-categories.js +0 -108
  183. package/dist/core/follow-up-history.d.ts +0 -40
  184. package/dist/core/follow-up-history.js +0 -71
  185. package/dist/core/issue-effort.d.ts +0 -29
  186. package/dist/core/issue-effort.js +0 -47
  187. package/dist/core/maintainer-hints.d.ts +0 -23
  188. package/dist/core/maintainer-hints.js +0 -36
  189. package/dist/core/workflow-state.d.ts +0 -56
  190. package/dist/core/workflow-state.js +0 -101
  191. package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
  192. package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
@@ -17,19 +17,31 @@ import { type ActivityEvent } from './review-analysis.js';
17
17
  import type { MergedPRActivity, MergedPRActivityList } from './merged-pr-notes.js';
18
18
  import type { ReviewedPRActivity, ReviewedPRActivityList } from './reviewed-prs.js';
19
19
  import { type CompareStatus, type ReviewedPRSearchResult } from './reviewed-prs-fetch.js';
20
- import { type PRCountsResult } from './github-stats.js';
20
+ import { type PRCountsResult, type RecentListTruncation } from './github-stats.js';
21
21
  export { computeDisplayLabel } from './display-utils.js';
22
22
  export { categorizeCIStatus, classifyCICheck, classifyFailingChecks, getCIStatus } from './ci-analysis.js';
23
23
  export { isConditionalChecklistItem } from './checklist-analysis.js';
24
24
  export { determineStatus } from './status-determination.js';
25
25
  /**
26
26
  * Check if a PR has a merge conflict based on GitHub's mergeable flag and mergeable_state.
27
- * Returns true when mergeable is explicitly false or the mergeable_state is 'dirty'.
27
+ * Returns true when mergeable is explicitly false or the mergeable_state is 'dirty',
28
+ * and null when GitHub has not computed mergeability yet (neither clean nor conflicted).
28
29
  *
29
30
  * @param mergeable - GitHub's mergeable flag (null when not yet computed)
30
31
  * @param mergeableState - GitHub's mergeable_state string
31
32
  */
32
- export declare function hasMergeConflict(mergeable: boolean | null, mergeableState: string | null): boolean;
33
+ export declare function hasMergeConflict(mergeable: boolean | null, mergeableState: string | null): boolean | null;
34
+ /** What one repository read gives the daily run; see PRMonitor.fetchRepoMetadata. */
35
+ export interface RepoMetadata {
36
+ stars: number;
37
+ language: string | null;
38
+ /**
39
+ * GitHub's `private` flag for the repository. Undefined when the response
40
+ * did not carry a boolean; never a guess. Repositories that could not be
41
+ * read are absent from the result altogether.
42
+ */
43
+ isPrivate?: boolean;
44
+ }
33
45
  export interface PRCheckFailure {
34
46
  prUrl: string;
35
47
  error: string;
@@ -99,6 +111,12 @@ export declare class PRMonitor {
99
111
  * the computed status is identical regardless of transport.
100
112
  */
101
113
  private fetchPRDetails;
114
+ /**
115
+ * Settle a merge-conflict answer GitHub left unknown after the re-query by
116
+ * reusing the previous run's value, so a known conflict is not hidden behind
117
+ * a waiting status for a run (#1915). No previous value means no conflict.
118
+ */
119
+ private resolveMergeConflict;
102
120
  /**
103
121
  * REST counterpart of the GraphQL `timelineItems` selection: commits (author
104
122
  * and committer) plus force-push / review-request / label events, used for
@@ -108,12 +126,18 @@ export declare class PRMonitor {
108
126
  */
109
127
  private fetchActivityEvents;
110
128
  /**
111
- * Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
129
+ * Fetch the HEAD commit's date (see {@link commitDateOf}) and author login via REST `repos.getCommit`.
112
130
  * Rate-limit errors propagate (silently swallowing them produces misleading
113
131
  * status, e.g. needs_changes when changes were addressed) (#469); other
114
132
  * failures degrade to `undefined` so the PR is still returned.
115
133
  */
116
134
  private fetchCommitInfo;
135
+ /**
136
+ * First parent of a commit, or undefined when it cannot be fetched (a
137
+ * force-pushed-away commit GitHub no longer serves): the date rule then
138
+ * treats the rebase as unknown (#2042). Rate-limit and auth errors propagate.
139
+ */
140
+ private fetchFirstParentSha;
117
141
  /**
118
142
  * Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
119
143
  * No network calls: the batch already carries the commit info, so it is
@@ -136,19 +160,17 @@ export declare class PRMonitor {
136
160
  */
137
161
  fetchUserClosedPRCounts(starFilter?: StarFilter): Promise<PRCountsResult<number>>;
138
162
  /**
139
- * Fetch metadata (star count and primary language) for a list of repositories.
140
- * Both fields come from the same `repos.get()` call — zero additional API cost.
163
+ * Fetch metadata (star count, primary language, visibility) for a list of repositories.
164
+ * All fields come from the same `repos.get()` call — zero additional API cost.
141
165
  */
142
- fetchRepoMetadata(repos: string[]): Promise<Map<string, {
143
- stars: number;
144
- language: string | null;
145
- }>>;
166
+ fetchRepoMetadata(repos: string[]): Promise<Map<string, RepoMetadata>>;
146
167
  /**
147
168
  * Fetch PRs closed without merge in the last N days.
148
169
  * @param days - Lookback window in days (default: 7)
170
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
149
171
  * @returns Recently closed PRs
150
172
  */
151
- fetchRecentlyClosedPRs(days?: number): Promise<ClosedPR[]>;
173
+ fetchRecentlyClosedPRs(days?: number, truncations?: RecentListTruncation[]): Promise<ClosedPR[]>;
152
174
  /**
153
175
  * Login of the account that closed a PR (#1863), or undefined when GitHub
154
176
  * reports none. The Search API items behind `fetchRecentlyClosedPRs` carry
@@ -163,9 +185,10 @@ export declare class PRMonitor {
163
185
  /**
164
186
  * Fetch PRs merged in the last N days.
165
187
  * @param days - Lookback window in days (default: 7)
188
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
166
189
  * @returns Recently merged PRs
167
190
  */
168
- fetchRecentlyMergedPRs(days?: number): Promise<MergedPR[]>;
191
+ fetchRecentlyMergedPRs(days?: number, truncations?: RecentListTruncation[]): Promise<MergedPR[]>;
169
192
  /**
170
193
  * Everything the merged-PR notes selection reads for one PR (#1861): issue
171
194
  * comments, reviews, inline review comments and commits, each paginated.
@@ -14,16 +14,18 @@
14
14
  */
15
15
  import { getOctokit } from './github.js';
16
16
  import { getStateManager } from './state.js';
17
- import { parseGitHubUrl, extractOwnerRepo, isOwnRepo, isUntrackedOrg } from './urls.js';
18
- import { DEFAULT_CONCURRENCY, rethrowRejections, runWorkerPool } from './concurrency.js';
17
+ import { parseGitHubUrl, extractOwnerRepo, isOwnRepo, isUntrackedOrg, findRefKey } from './urls.js';
18
+ import { DEFAULT_CONCURRENCY, rethrowRejections, runWorkerPool, sleep } from './concurrency.js';
19
19
  import { ConfigurationError, ValidationError, errorMessage, getHttpStatusCode, isInvalidUserSearchError, isRateLimitOrAuthError, } from './errors.js';
20
20
  import { paginateAllDetailed } from './pagination.js';
21
21
  import { debug, warn, timed } from './logger.js';
22
22
  import { getHttpCache, cachedRequest } from './http-cache.js';
23
23
  import { getCIStatus } from './ci-analysis.js';
24
+ import { getChangesRequestedCommitSha } from './review-analysis.js';
24
25
  import { fetchCompareStatus as fetchCompareStatusImpl, fetchReviewedOpenPRs as fetchReviewedOpenPRsImpl, fetchReviewedPRActivity as fetchReviewedPRActivityImpl, } from './reviewed-prs-fetch.js';
26
+ import { commitDateOf, isOwnRewrite } from './commit-date.js';
25
27
  import { assembleFetchedPR } from './pr-assembly.js';
26
- import { batchFetchPRDetails } from './pr-graphql.js';
28
+ import { batchFetchPRDetails, MERGEABLE_RETRY_DELAY_MS, PR_FETCH_LOG, } from './pr-graphql.js';
27
29
  import { fetchUserMergedPRCounts as fetchUserMergedPRCountsImpl, fetchUserClosedPRCounts as fetchUserClosedPRCountsImpl, fetchRecentlyClosedPRs as fetchRecentlyClosedPRsImpl, fetchRecentlyMergedPRs as fetchRecentlyMergedPRsImpl, } from './github-stats.js';
28
30
  import { isPlaceholderUsername } from './placeholder-usernames.js';
29
31
  // Re-export so existing consumers can still import from pr-monitor
@@ -33,13 +35,16 @@ export { isConditionalChecklistItem } from './checklist-analysis.js';
33
35
  export { determineStatus } from './status-determination.js';
34
36
  /**
35
37
  * Check if a PR has a merge conflict based on GitHub's mergeable flag and mergeable_state.
36
- * Returns true when mergeable is explicitly false or the mergeable_state is 'dirty'.
38
+ * Returns true when mergeable is explicitly false or the mergeable_state is 'dirty',
39
+ * and null when GitHub has not computed mergeability yet (neither clean nor conflicted).
37
40
  *
38
41
  * @param mergeable - GitHub's mergeable flag (null when not yet computed)
39
42
  * @param mergeableState - GitHub's mergeable_state string
40
43
  */
41
44
  export function hasMergeConflict(mergeable, mergeableState) {
42
- return mergeable === false || mergeableState === 'dirty';
45
+ if (mergeable === false || mergeableState === 'dirty')
46
+ return true;
47
+ return mergeable === null ? null : false;
43
48
  }
44
49
  const MODULE = 'pr-monitor';
45
50
  const MAX_CONCURRENT_REQUESTS = DEFAULT_CONCURRENCY;
@@ -49,6 +54,22 @@ function fulfilledValue(result) {
49
54
  throw result.reason;
50
55
  return result.value;
51
56
  }
57
+ function firstParentSha(data) {
58
+ return data.parents?.[0]?.sha;
59
+ }
60
+ /** The date-rule inputs of a REST `repos.getCommit` response (#1919, #2042). */
61
+ function restCommitDates(data, reviewedSha) {
62
+ return {
63
+ authorDate: data.commit.author?.date,
64
+ committerDate: data.commit.committer?.date,
65
+ authorLogin: data.author?.login,
66
+ committerLogin: data.committer?.login,
67
+ authorEmail: data.commit.author?.email,
68
+ committerEmail: data.commit.committer?.email,
69
+ parentSha: firstParentSha(data),
70
+ reviewedSha,
71
+ };
72
+ }
52
73
  /**
53
74
  * Fetches and enriches open PRs from GitHub for the configured user.
54
75
  *
@@ -259,7 +280,7 @@ export class PRMonitor {
259
280
  // the common case in a handful of ~1-point queries; anything it can't resolve
260
281
  // (connection cap overflow, missing node, GraphQL outage) falls back to the
261
282
  // per-PR REST path via the worker pool.
262
- await timed('pr-monitor', `Fetch details for ${refs.length} PRs`, async () => {
283
+ await timed('pr-monitor', `${PR_FETCH_LOG.fetchDetails} ${refs.length} PRs`, async () => {
263
284
  let batch;
264
285
  try {
265
286
  batch = await batchFetchPRDetails(this.octokit, refs);
@@ -268,7 +289,7 @@ export class PRMonitor {
268
289
  // A fatal batch-level GraphQL error (rate limit / auth). Don't crash the
269
290
  // run — route every PR to the REST path, which surfaces per-PR failures
270
291
  // exactly as the pre-GraphQL implementation did.
271
- warn(MODULE, `GraphQL batch enrichment failed (${errorMessage(error)}); falling back to REST for all PRs`);
292
+ warn(MODULE, `${PR_FETCH_LOG.enrichmentFailed} (${errorMessage(error)}); falling back to REST for all PRs`);
272
293
  batch = { resolved: new Map(), restFallbackUrls: refs.map((r) => r.url) };
273
294
  }
274
295
  // Assemble GraphQL-resolved PRs (no additional network calls).
@@ -281,14 +302,14 @@ export class PRMonitor {
281
302
  }
282
303
  catch (error) {
283
304
  const errMsg = errorMessage(error);
284
- warn('pr-monitor', `Error assembling ${url}: ${errMsg}`);
305
+ warn('pr-monitor', `${PR_FETCH_LOG.assembleFailed} ${url}: ${errMsg}`);
285
306
  failures.push({ prUrl: url, error: errMsg });
286
307
  }
287
308
  }
288
309
  // REST fallback for the remainder, using a worker pool for bounded concurrency.
289
310
  await runWorkerPool(batch.restFallbackUrls, async (url) => {
290
311
  try {
291
- debug('pr-monitor', `Fetching details for ${url} (REST fallback)`);
312
+ debug('pr-monitor', `Fetching details for ${url} ${PR_FETCH_LOG.restFallback}`);
292
313
  const pr = await this.fetchPRDetails(url, warnings);
293
314
  if (pr)
294
315
  prs.push(pr);
@@ -353,6 +374,7 @@ export class PRMonitor {
353
374
  }
354
375
  // Non-rate-limit 403 (DMCA, private repo, SSO) — degrade gracefully
355
376
  warn('pr-monitor', `403 fetching review comments for ${owner}/${repo}#${number}: ${msg}`);
377
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- pins the Promise.all element type for the fallback branch
356
378
  return { items: [], truncated: false };
357
379
  }
358
380
  if (status === 404) {
@@ -361,6 +383,7 @@ export class PRMonitor {
361
383
  else {
362
384
  warn('pr-monitor', `Failed to fetch review comments for ${owner}/${repo}#${number} (status ${status ?? 'unknown'}): self-reply detection will be skipped`);
363
385
  }
386
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- pins the Promise.all element type for the fallback branch
364
387
  return { items: [], truncated: false };
365
388
  }),
366
389
  ]);
@@ -378,6 +401,21 @@ export class PRMonitor {
378
401
  }
379
402
  const ghPR = prResponse.data;
380
403
  const reviews = reviewsResult.items;
404
+ // GitHub computes mergeability lazily: the first `pulls.get` starts the job
405
+ // and can answer null. Ask once more after a short delay (#1915).
406
+ let mergeConflict = hasMergeConflict(ghPR.mergeable, ghPR.mergeable_state);
407
+ if (mergeConflict === null) {
408
+ await sleep(MERGEABLE_RETRY_DELAY_MS);
409
+ try {
410
+ const { data } = await this.octokit.pulls.get({ owner, repo, pull_number: number });
411
+ mergeConflict = hasMergeConflict(data.mergeable, data.mergeable_state);
412
+ }
413
+ catch (err) {
414
+ if (isRateLimitOrAuthError(err))
415
+ throw err;
416
+ warn(MODULE, `Mergeability re-query failed for ${owner}/${repo}#${number}: ${errorMessage(err)}`);
417
+ }
418
+ }
381
419
  const activityEvents = await this.fetchActivityEvents(owner, repo, number);
382
420
  const ciStatus = await getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
383
421
  // The commit date is only consulted (and only fetched) when the PR has an
@@ -385,9 +423,10 @@ export class PRMonitor {
385
423
  // pipeline decides via `needCommitDate` and invokes this thunk lazily.
386
424
  // A PR with a status override is the exception: override auto-clear keys
387
425
  // on the commit date (#1713), so fetch it up front for those PRs only.
388
- const commitInfo = config.statusOverrides?.[prUrl]
389
- ? await this.fetchCommitInfo(owner, repo, ghPR.head.sha)
390
- : () => this.fetchCommitInfo(owner, repo, ghPR.head.sha);
426
+ const reviewedSha = getChangesRequestedCommitSha(reviews);
427
+ const commitInfo = findRefKey(config.statusOverrides, prUrl)
428
+ ? await this.fetchCommitInfo(owner, repo, ghPR.head.sha, reviewedSha)
429
+ : () => this.fetchCommitInfo(owner, repo, ghPR.head.sha, reviewedSha);
391
430
  return assembleFetchedPR({
392
431
  prUrl,
393
432
  owner,
@@ -398,7 +437,7 @@ export class PRMonitor {
398
437
  body: ghPR.body || '',
399
438
  createdAt: ghPR.created_at,
400
439
  updatedAt: ghPR.updated_at,
401
- hasMergeConflict: hasMergeConflict(ghPR.mergeable, ghPR.mergeable_state),
440
+ hasMergeConflict: this.resolveMergeConflict(prUrl, mergeConflict),
402
441
  comments,
403
442
  reviews,
404
443
  reviewComments,
@@ -406,6 +445,19 @@ export class PRMonitor {
406
445
  ciStatus,
407
446
  }, config, commitInfo);
408
447
  }
448
+ /**
449
+ * Settle a merge-conflict answer GitHub left unknown after the re-query by
450
+ * reusing the previous run's value, so a known conflict is not hidden behind
451
+ * a waiting status for a run (#1915). No previous value means no conflict.
452
+ */
453
+ resolveMergeConflict(prUrl, fresh) {
454
+ if (fresh !== null)
455
+ return fresh;
456
+ const previous = this.stateManager.getState().lastDigest?.openPRs.find((pr) => pr.url === prUrl);
457
+ const wasConflicted = previous?.hasMergeConflict ?? false;
458
+ warn(MODULE, `Mergeability still unknown for ${prUrl}; assuming conflict=${wasConflicted} from the previous run`);
459
+ return wasConflicted;
460
+ }
409
461
  /**
410
462
  * REST counterpart of the GraphQL `timelineItems` selection: commits (author
411
463
  * and committer) plus force-push / review-request / label events, used for
@@ -429,16 +481,22 @@ export class PRMonitor {
429
481
  }
430
482
  }
431
483
  /**
432
- * Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
484
+ * Fetch the HEAD commit's date (see {@link commitDateOf}) and author login via REST `repos.getCommit`.
433
485
  * Rate-limit errors propagate (silently swallowing them produces misleading
434
486
  * status, e.g. needs_changes when changes were addressed) (#469); other
435
487
  * failures degrade to `undefined` so the PR is still returned.
436
488
  */
437
- async fetchCommitInfo(owner, repo, sha) {
489
+ async fetchCommitInfo(owner, repo, sha, reviewedSha) {
438
490
  try {
439
491
  const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
492
+ const dates = restCommitDates(res.data, reviewedSha);
493
+ // The reviewed commit's parent only matters for the author's own rewrite
494
+ // of a commit other than the reviewed one, so fetch it only then.
495
+ if (reviewedSha && reviewedSha !== sha && isOwnRewrite(dates)) {
496
+ dates.reviewedParentSha = await this.fetchFirstParentSha(owner, repo, reviewedSha);
497
+ }
440
498
  return {
441
- date: res.data.commit.author?.date,
499
+ date: commitDateOf(dates),
442
500
  // GitHub user login of the commit author (may differ from git author)
443
501
  author: res.data.author?.login,
444
502
  };
@@ -459,6 +517,23 @@ export class PRMonitor {
459
517
  return undefined;
460
518
  }
461
519
  }
520
+ /**
521
+ * First parent of a commit, or undefined when it cannot be fetched (a
522
+ * force-pushed-away commit GitHub no longer serves): the date rule then
523
+ * treats the rebase as unknown (#2042). Rate-limit and auth errors propagate.
524
+ */
525
+ async fetchFirstParentSha(owner, repo, sha) {
526
+ try {
527
+ const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
528
+ return firstParentSha(res.data);
529
+ }
530
+ catch (err) {
531
+ if (isRateLimitOrAuthError(err))
532
+ throw err;
533
+ warn(MODULE, `Failed to fetch reviewed commit ${owner}/${repo}@${sha.slice(0, 7)}: ${errorMessage(err)}`);
534
+ return undefined;
535
+ }
536
+ }
462
537
  /**
463
538
  * Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
464
539
  * No network calls: the batch already carries the commit info, so it is
@@ -476,7 +551,7 @@ export class PRMonitor {
476
551
  body: data.body,
477
552
  createdAt: data.createdAt,
478
553
  updatedAt: data.updatedAt,
479
- hasMergeConflict: data.hasMergeConflict,
554
+ hasMergeConflict: this.resolveMergeConflict(ref.url, data.hasMergeConflict),
480
555
  comments: data.comments,
481
556
  reviews: data.reviews,
482
557
  reviewComments: data.reviewComments,
@@ -491,7 +566,7 @@ export class PRMonitor {
491
566
  */
492
567
  async fetchUserMergedPRCounts(starFilter) {
493
568
  const config = this.stateManager.getState().config;
494
- return fetchUserMergedPRCountsImpl(this.octokit, config.githubUsername, starFilter);
569
+ return fetchUserMergedPRCountsImpl(this.octokit, config.githubUsername, starFilter, config.untrackedOrgs);
495
570
  }
496
571
  /**
497
572
  * Fetch closed-without-merge PR counts per repository for the configured user.
@@ -500,11 +575,11 @@ export class PRMonitor {
500
575
  */
501
576
  async fetchUserClosedPRCounts(starFilter) {
502
577
  const config = this.stateManager.getState().config;
503
- return fetchUserClosedPRCountsImpl(this.octokit, config.githubUsername, starFilter);
578
+ return fetchUserClosedPRCountsImpl(this.octokit, config.githubUsername, starFilter, config.untrackedOrgs);
504
579
  }
505
580
  /**
506
- * Fetch metadata (star count and primary language) for a list of repositories.
507
- * Both fields come from the same `repos.get()` call — zero additional API cost.
581
+ * Fetch metadata (star count, primary language, visibility) for a list of repositories.
582
+ * All fields come from the same `repos.get()` call — zero additional API cost.
508
583
  */
509
584
  async fetchRepoMetadata(repos) {
510
585
  if (repos.length === 0)
@@ -530,7 +605,14 @@ export class PRMonitor {
530
605
  repo: name,
531
606
  headers,
532
607
  }));
533
- const metadata = { stars: data.stargazers_count, language: data.language ?? null };
608
+ const metadata = {
609
+ stars: data.stargazers_count,
610
+ language: data.language ?? null,
611
+ // The whole response body is what the ETag cache stores, so a 304
612
+ // answers from a body that carries the flag too. Anything but a
613
+ // boolean (an unexpected body) reads as unknown.
614
+ isPrivate: typeof data.private === 'boolean' ? data.private : undefined,
615
+ };
534
616
  return { repo, metadata };
535
617
  }));
536
618
  let chunkFailures = 0;
@@ -559,11 +641,12 @@ export class PRMonitor {
559
641
  /**
560
642
  * Fetch PRs closed without merge in the last N days.
561
643
  * @param days - Lookback window in days (default: 7)
644
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
562
645
  * @returns Recently closed PRs
563
646
  */
564
- async fetchRecentlyClosedPRs(days = 7) {
647
+ async fetchRecentlyClosedPRs(days = 7, truncations) {
565
648
  const config = this.stateManager.getState().config;
566
- return fetchRecentlyClosedPRsImpl(this.octokit, config, days);
649
+ return fetchRecentlyClosedPRsImpl(this.octokit, config, days, truncations);
567
650
  }
568
651
  /**
569
652
  * Login of the account that closed a PR (#1863), or undefined when GitHub
@@ -590,11 +673,12 @@ export class PRMonitor {
590
673
  /**
591
674
  * Fetch PRs merged in the last N days.
592
675
  * @param days - Lookback window in days (default: 7)
676
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
593
677
  * @returns Recently merged PRs
594
678
  */
595
- async fetchRecentlyMergedPRs(days = 7) {
679
+ async fetchRecentlyMergedPRs(days = 7, truncations) {
596
680
  const config = this.stateManager.getState().config;
597
- return fetchRecentlyMergedPRsImpl(this.octokit, config, days);
681
+ return fetchRecentlyMergedPRsImpl(this.octokit, config, days, truncations);
598
682
  }
599
683
  /**
600
684
  * Everything the merged-PR notes selection reads for one PR (#1861): issue
@@ -0,0 +1,154 @@
1
+ /**
2
+ * PR preflight checks (#1952): the gate that runs before a branch is pushed
3
+ * and a PR is opened in someone else's repository.
4
+ *
5
+ * Every check is a pure function over `PreflightFacts`, which the
6
+ * `pr-preflight` command gathers from the local clone and read-only GitHub calls.
7
+ * A new check is one more function in `PREFLIGHT_CHECKS` (plus the facts it
8
+ * needs); the verdict and the output shape do not change.
9
+ */
10
+ import type { IssueVerification } from './issue-verification.js';
11
+ import type { PacingStatus } from './pacing.js';
12
+ import { type RepoScripts } from './prose-script.js';
13
+ import type { RepoCapStatus } from './repo-cap.js';
14
+ import { type RepoPolicy } from './repo-policy.js';
15
+ export type PreflightStatus = 'pass' | 'warn' | 'fail' | 'skipped';
16
+ export type PreflightVerdict = 'pass' | 'warn' | 'fail';
17
+ export interface PreflightCheck {
18
+ id: string;
19
+ status: PreflightStatus;
20
+ /** One line a user can read. */
21
+ summary: string;
22
+ /** The facts behind the status. Commit subjects in it arrive inside a `<github-content>` fence. */
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /** What GitHub says about the upstream repository; absent without a token. */
26
+ export interface PreflightGitHubFacts {
27
+ defaultBranch: string;
28
+ /** `owner/repo` the upstream repository was forked from, or null. */
29
+ parent: string | null;
30
+ /** The token can push to the upstream repository. */
31
+ canPush: boolean;
32
+ /** Head commit of the target branch on GitHub; null when the branch does not exist there. */
33
+ baseHeadSha: string | null;
34
+ }
35
+ export interface PreflightFacts {
36
+ /** Upstream `owner/repo`: from the issue URL, else from the remote. Null when neither names a GitHub repository. */
37
+ repo: string | null;
38
+ /** Remote the drift is measured against; null when the clone has none. */
39
+ remote: string | null;
40
+ /** `owner/repo` that remote's URL points at. */
41
+ remoteRepo: string | null;
42
+ /** Current branch; null on a detached HEAD. */
43
+ branch: string | null;
44
+ /** Branch the PR will target: `--base`, else the default branch. */
45
+ base: string | null;
46
+ /** Default branch the clone records for the remote (`refs/remotes/<remote>/HEAD`). */
47
+ localDefault: string | null;
48
+ /** Entries in `git status --porcelain`. */
49
+ dirtyCount: number;
50
+ /** Commit the local `<remote>/<base>` ref points at; null when it is not fetched. */
51
+ remoteRefSha: string | null;
52
+ behind: number | null;
53
+ ahead: number | null;
54
+ mergeBase: string | null;
55
+ /** `git log --oneline` lines for upstream commits since the merge base that touch files this branch changed. */
56
+ overlappingCommits: string[];
57
+ /** Full messages of this branch's own commits (`git log <mergeBase>..HEAD`, merges left out); null without a merge base. */
58
+ branchCommits: string[] | null;
59
+ /** Set when `--fetch` was passed and the fetch failed. */
60
+ fetchError: string | null;
61
+ /** Configured GitHub username. */
62
+ login: string | null;
63
+ /** Remote whose URL owner is `login`. */
64
+ pushRemote: string | null;
65
+ issueUrl: string | null;
66
+ /** Why GitHub was not consulted at all (`--local`, no token, no GitHub remote); null when it was. */
67
+ networkSkip: string | null;
68
+ /** Why one GitHub read failed; that check degrades and the others still run. */
69
+ githubError: string | null;
70
+ issueError: string | null;
71
+ capError: string | null;
72
+ github: PreflightGitHubFacts | null;
73
+ issue: IssueVerification | null;
74
+ cap: RepoCapStatus | null;
75
+ /** The pacing caps that are set, counted from local state (#1911); null when neither is set. */
76
+ pacing: PacingStatus | null;
77
+ /** The repo's contribution policy (`effectivePolicy`: stored record plus the blocklist); null when none is recorded. */
78
+ policy: RepoPolicy | null;
79
+ /** The user has no merged PR in the repo. */
80
+ isFirstContribution: boolean;
81
+ /** The staged PR body (`--body-file`); null when none was given. */
82
+ prBody: string | null;
83
+ /** The scripts the repo's README and CONTRIBUTING are written in; null when not read (no GitHub, or no staged text). */
84
+ repoScripts: RepoScripts | null;
85
+ /** The repo's PR template (`--template-file`); body lines found in it are not counted as prose. */
86
+ prTemplate: string | null;
87
+ /** The staged PR title (`--title-file`); null when none was given. */
88
+ prTitle: string | null;
89
+ /** `--allow-script-mismatch`: a script mismatch warns instead of failing. */
90
+ allowScriptMismatch: boolean;
91
+ /** The PR will be opened as a draft (`--draft`). */
92
+ isDraft: boolean;
93
+ /** The issue's label names, read only for a `maintainer-label` gate; null when not read. */
94
+ issueLabels: string[] | null;
95
+ /** Why the label read failed. */
96
+ labelsError: string | null;
97
+ }
98
+ /** Past this many commits behind, the drift check warns even when no upstream commit touches the branch's files. */
99
+ export declare const BEHIND_WARN_THRESHOLD = 20;
100
+ /**
101
+ * Commits on the upstream target branch that this branch does not have. Never fetches: a stale ref is reported.
102
+ * The local ref is compared with GitHub only when its remote points at the upstream repository; in a
103
+ * fork-only clone the two are different branches, and "stale, fetch again" would never clear.
104
+ */
105
+ export declare function checkDrift(facts: PreflightFacts): PreflightCheck;
106
+ /** The PR targets a branch that exists upstream and is the default branch, on the repository the remote points at. */
107
+ export declare function checkBaseBranch(facts: PreflightFacts): PreflightCheck;
108
+ /** The head is a real feature branch, and the user has somewhere to push it. */
109
+ export declare function checkHeadBranch(facts: PreflightFacts): PreflightCheck;
110
+ export declare function checkWorkingTree(facts: PreflightFacts): PreflightCheck;
111
+ /** Someone else's open closing PR, an assignment, or a closed issue, from the same verification `verify-issue` runs. */
112
+ export declare function checkCompetingWork(facts: PreflightFacts): PreflightCheck;
113
+ /** The user's own open-PR cap and `excludeRepos`, as `repo-cap` reports them. Runs only for an issue: it gates a new PR. */
114
+ export declare function checkRepoCap(facts: PreflightFacts): PreflightCheck;
115
+ /**
116
+ * The optional pacing caps (#1911). Runs only for an issue, like `repo-cap`:
117
+ * it gates a new PR, never a push to an existing one. The fork cap applies
118
+ * when the PR needs a new fork: no remote of the user's and no push access.
119
+ * A `fail` here defers the PR: the branch stays local and nothing is lost.
120
+ */
121
+ export declare function checkPacing(facts: PreflightFacts): PreflightCheck;
122
+ /**
123
+ * The repo's contribution policy (#1953): `banned` fails, a rule the PR has
124
+ * not met warns with the action that meets it. Quoted repo text arrives fenced.
125
+ */
126
+ export declare function checkRepoPolicy(facts: PreflightFacts): PreflightCheck;
127
+ /**
128
+ * The repo's recorded commit rules over this branch's commits (local, no
129
+ * network). A rule the user confirmed fails; one read from the docs and not
130
+ * reviewed only warns. Commit subjects arrive fenced.
131
+ */
132
+ export declare function checkCommitRules(facts: PreflightFacts): PreflightCheck;
133
+ /** The title opens with a work-in-progress marker (#1910, #2087). */
134
+ export declare function hasWipMarker(title: string): boolean;
135
+ /**
136
+ * The staged title and body are ready to publish (#1910): the body says
137
+ * something beyond what the PR template brings ({@link bodyProse}), and a
138
+ * PR that is not a draft has no WIP marker in its title. Nothing is filled in.
139
+ */
140
+ export declare function checkPrDescription(facts: PreflightFacts): PreflightCheck;
141
+ /**
142
+ * The staged title and body are in the script the repo writes in (#1909). A
143
+ * script check, not language detection: Latin-script languages are not told
144
+ * apart. Without the repo's docs, English (Latin script) is assumed and said so.
145
+ */
146
+ export declare function checkPrLanguage(facts: PreflightFacts): PreflightCheck;
147
+ /** Every check, in output order. A new check is added here. */
148
+ export declare const PREFLIGHT_CHECKS: ReadonlyArray<(facts: PreflightFacts) => PreflightCheck>;
149
+ /** `fail` when any check fails, else `warn` when any warns, else `pass`. Skipped checks do not count. */
150
+ export declare function preflightVerdict(checks: readonly PreflightCheck[]): PreflightVerdict;
151
+ export declare function runPreflightChecks(facts: PreflightFacts): {
152
+ verdict: PreflightVerdict;
153
+ checks: PreflightCheck[];
154
+ };