@oss-autopilot/core 3.42.4 → 3.43.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 (172) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +272 -25
  3. package/dist/cli.bundle.cjs +183 -154
  4. package/dist/commands/check-integration.js +1 -0
  5. package/dist/commands/cleanup.d.ts +76 -0
  6. package/dist/commands/cleanup.js +269 -0
  7. package/dist/commands/comments.d.ts +6 -0
  8. package/dist/commands/comments.js +6 -2
  9. package/dist/commands/config.js +37 -5
  10. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  11. package/dist/commands/daily-dismiss-filter.js +17 -1
  12. package/dist/commands/daily-ledger.d.ts +122 -0
  13. package/dist/commands/daily-ledger.js +225 -0
  14. package/dist/commands/daily-recent-prs.d.ts +26 -0
  15. package/dist/commands/daily-recent-prs.js +55 -0
  16. package/dist/commands/daily.d.ts +2 -1
  17. package/dist/commands/daily.js +59 -89
  18. package/dist/commands/dashboard-cache.d.ts +2 -0
  19. package/dist/commands/dashboard-cache.js +33 -8
  20. package/dist/commands/dashboard-data.js +71 -36
  21. package/dist/commands/dashboard-gist-sync.js +3 -1
  22. package/dist/commands/dashboard-lifecycle.js +1 -1
  23. package/dist/commands/dashboard-process.d.ts +14 -1
  24. package/dist/commands/dashboard-process.js +46 -7
  25. package/dist/commands/dashboard-server.js +89 -23
  26. package/dist/commands/detect-formatters.js +1 -0
  27. package/dist/commands/dismiss.js +5 -2
  28. package/dist/commands/doctor.d.ts +15 -1
  29. package/dist/commands/doctor.js +73 -5
  30. package/dist/commands/draft.d.ts +77 -0
  31. package/dist/commands/draft.js +218 -0
  32. package/dist/commands/eval.js +1 -0
  33. package/dist/commands/guidelines.d.ts +23 -1
  34. package/dist/commands/guidelines.js +49 -4
  35. package/dist/commands/index.d.ts +24 -4
  36. package/dist/commands/index.js +15 -3
  37. package/dist/commands/issue-thread.d.ts +46 -0
  38. package/dist/commands/issue-thread.js +123 -0
  39. package/dist/commands/ledger-backfill.d.ts +9 -0
  40. package/dist/commands/ledger-backfill.js +44 -1
  41. package/dist/commands/list-mark-done.d.ts +2 -1
  42. package/dist/commands/list-mark-done.js +3 -1
  43. package/dist/commands/list-move-tier.d.ts +2 -1
  44. package/dist/commands/list-move-tier.js +3 -1
  45. package/dist/commands/local-repos.js +10 -5
  46. package/dist/commands/locate-issue-list.d.ts +40 -17
  47. package/dist/commands/locate-issue-list.js +148 -88
  48. package/dist/commands/move.js +7 -1
  49. package/dist/commands/overnight-handoff.d.ts +17 -7
  50. package/dist/commands/overnight-handoff.js +36 -14
  51. package/dist/commands/overnight-push-prep.d.ts +13 -8
  52. package/dist/commands/overnight-push-prep.js +106 -34
  53. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  54. package/dist/commands/overnight-tool-rules.js +217 -0
  55. package/dist/commands/overnight.d.ts +5 -6
  56. package/dist/commands/overnight.js +61 -140
  57. package/dist/commands/parse-list.js +7 -1
  58. package/dist/commands/policy.d.ts +86 -0
  59. package/dist/commands/policy.js +263 -0
  60. package/dist/commands/pr-preflight.d.ts +43 -0
  61. package/dist/commands/pr-preflight.js +294 -0
  62. package/dist/commands/repo-vet.d.ts +9 -0
  63. package/dist/commands/repo-vet.js +36 -11
  64. package/dist/commands/scout-bridge.js +18 -8
  65. package/dist/commands/search.js +7 -0
  66. package/dist/commands/setup.d.ts +3 -3
  67. package/dist/commands/setup.js +46 -18
  68. package/dist/commands/skip-add.js +10 -1
  69. package/dist/commands/startup.d.ts +5 -3
  70. package/dist/commands/startup.js +65 -49
  71. package/dist/commands/state-cmd.d.ts +2 -0
  72. package/dist/commands/state-cmd.js +5 -1
  73. package/dist/commands/stats.js +1 -0
  74. package/dist/commands/status.js +1 -0
  75. package/dist/commands/strategy.js +1 -0
  76. package/dist/commands/vet-list.d.ts +6 -0
  77. package/dist/commands/vet-list.js +25 -0
  78. package/dist/commands/vet.d.ts +12 -0
  79. package/dist/commands/vet.js +118 -1
  80. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  81. package/dist/core/anti-llm-policy.d.ts +3 -0
  82. package/dist/core/anti-llm-policy.js +3 -0
  83. package/dist/core/auth.js +2 -0
  84. package/dist/core/checklist-analysis.js +50 -12
  85. package/dist/core/ci-analysis.d.ts +7 -2
  86. package/dist/core/ci-analysis.js +76 -21
  87. package/dist/core/comment-utils.d.ts +1 -1
  88. package/dist/core/comment-utils.js +7 -1
  89. package/dist/core/commit-date.d.ts +19 -0
  90. package/dist/core/commit-date.js +17 -0
  91. package/dist/core/compliance-score.js +11 -7
  92. package/dist/core/config-registry.js +11 -5
  93. package/dist/core/contributing.d.ts +2 -3
  94. package/dist/core/contributing.js +2 -3
  95. package/dist/core/daily-logic.d.ts +27 -5
  96. package/dist/core/daily-logic.js +57 -19
  97. package/dist/core/errors.d.ts +37 -3
  98. package/dist/core/errors.js +54 -5
  99. package/dist/core/gist-health.d.ts +15 -3
  100. package/dist/core/gist-health.js +8 -0
  101. package/dist/core/gist-state-store.d.ts +24 -4
  102. package/dist/core/gist-state-store.js +97 -46
  103. package/dist/core/github-stats.d.ts +104 -16
  104. package/dist/core/github-stats.js +282 -97
  105. package/dist/core/http-cache.d.ts +0 -10
  106. package/dist/core/http-cache.js +0 -19
  107. package/dist/core/index.d.ts +12 -5
  108. package/dist/core/index.js +15 -5
  109. package/dist/core/issue-conversation.d.ts +8 -2
  110. package/dist/core/issue-conversation.js +31 -12
  111. package/dist/core/local-config.d.ts +95 -0
  112. package/dist/core/local-config.js +271 -0
  113. package/dist/core/merged-pr-notes.d.ts +2 -2
  114. package/dist/core/pagination.d.ts +55 -0
  115. package/dist/core/pagination.js +59 -0
  116. package/dist/core/paths.d.ts +7 -0
  117. package/dist/core/paths.js +9 -0
  118. package/dist/core/pr-assembly.js +6 -2
  119. package/dist/core/pr-graphql.d.ts +37 -3
  120. package/dist/core/pr-graphql.js +73 -12
  121. package/dist/core/pr-monitor.d.ts +29 -12
  122. package/dist/core/pr-monitor.js +71 -23
  123. package/dist/core/pr-preflight.d.ts +113 -0
  124. package/dist/core/pr-preflight.js +364 -0
  125. package/dist/core/pr-quality-rubric.d.ts +0 -6
  126. package/dist/core/pr-quality-rubric.js +0 -8
  127. package/dist/core/pr-template.d.ts +2 -0
  128. package/dist/core/pr-template.js +5 -1
  129. package/dist/core/repo-policy.d.ts +105 -0
  130. package/dist/core/repo-policy.js +400 -0
  131. package/dist/core/repo-score-manager.d.ts +48 -0
  132. package/dist/core/repo-score-manager.js +111 -1
  133. package/dist/core/review-analysis.d.ts +34 -19
  134. package/dist/core/review-analysis.js +74 -19
  135. package/dist/core/reviewed-prs-fetch.js +11 -29
  136. package/dist/core/reviewed-prs.js +8 -15
  137. package/dist/core/stale-data.d.ts +41 -0
  138. package/dist/core/stale-data.js +115 -0
  139. package/dist/core/state-persistence.d.ts +62 -27
  140. package/dist/core/state-persistence.js +338 -117
  141. package/dist/core/state-schema.d.ts +113 -210
  142. package/dist/core/state-schema.js +165 -80
  143. package/dist/core/state.d.ts +60 -8
  144. package/dist/core/state.js +192 -46
  145. package/dist/core/status-determination.js +26 -8
  146. package/dist/core/strategy.js +3 -1
  147. package/dist/core/types.d.ts +22 -1
  148. package/dist/core/types.js +1 -0
  149. package/dist/core/untrusted-content.d.ts +30 -11
  150. package/dist/core/untrusted-content.js +77 -42
  151. package/dist/core/urls.d.ts +9 -0
  152. package/dist/core/urls.js +18 -0
  153. package/dist/dashboard/assets/{chart-panel-DPKNBUts.js → chart-panel-C_C1lFTI.js} +1 -1
  154. package/dist/dashboard/assets/{index-B25bZOYX.js → index-B--H66Jk.js} +1 -1
  155. package/dist/dashboard/index.html +1 -1
  156. package/dist/formatters/json.d.ts +262 -6
  157. package/dist/formatters/json.js +77 -1
  158. package/package.json +1 -1
  159. package/dist/core/ci-enforced-tools.d.ts +0 -35
  160. package/dist/core/ci-enforced-tools.js +0 -109
  161. package/dist/core/comment-decision.d.ts +0 -79
  162. package/dist/core/comment-decision.js +0 -82
  163. package/dist/core/extraction-categories.d.ts +0 -55
  164. package/dist/core/extraction-categories.js +0 -108
  165. package/dist/core/follow-up-history.d.ts +0 -40
  166. package/dist/core/follow-up-history.js +0 -71
  167. package/dist/core/issue-effort.d.ts +0 -29
  168. package/dist/core/issue-effort.js +0 -47
  169. package/dist/core/maintainer-hints.d.ts +0 -23
  170. package/dist/core/maintainer-hints.js +0 -36
  171. package/dist/core/workflow-state.d.ts +0 -56
  172. package/dist/core/workflow-state.js +0 -101
@@ -75,6 +75,13 @@ export declare function getGistIdPath(): string;
75
75
  * share an id.
76
76
  */
77
77
  export declare function getMachineIdPath(): string;
78
+ /**
79
+ * Returns the path to the per-machine settings file (`~/.oss-autopilot/local-config.json`).
80
+ *
81
+ * Holds values that are only valid on this machine (#1950): filesystem paths
82
+ * and the local repo cache. It is local only: the Gist never carries it.
83
+ */
84
+ export declare function getLocalConfigPath(): string;
78
85
  /**
79
86
  * Returns the path to the local state cache file (`~/.oss-autopilot/state-cache.json`).
80
87
  *
@@ -128,6 +128,15 @@ export function getGistIdPath() {
128
128
  export function getMachineIdPath() {
129
129
  return path.join(getDataDir(), 'machine-id');
130
130
  }
131
+ /**
132
+ * Returns the path to the per-machine settings file (`~/.oss-autopilot/local-config.json`).
133
+ *
134
+ * Holds values that are only valid on this machine (#1950): filesystem paths
135
+ * and the local repo cache. It is local only: the Gist never carries it.
136
+ */
137
+ export function getLocalConfigPath() {
138
+ return path.join(getDataDir(), 'local-config.json');
139
+ }
131
140
  /**
132
141
  * Returns the path to the local state cache file (`~/.oss-autopilot/state-cache.json`).
133
142
  *
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { daysBetween } from './dates.js';
13
13
  import { determineStatus } from './status-determination.js';
14
- import { determineReviewDecision, getLatestChangesRequestedDate, checkUnrespondedComments, getFirstMaintainerResponseAt, getLastMaintainerActivity, } from './review-analysis.js';
14
+ import { determineReviewDecision, getLatestChangesRequestedDate, getStandingApprovalDate, checkUnrespondedComments, getFirstMaintainerResponseAt, getLastMaintainerActivity, } from './review-analysis.js';
15
15
  import { analyzeChecklist } from './checklist-analysis.js';
16
16
  import { closingIssueUrl, mentionedIssueUrls } from './github-stats.js';
17
17
  import { extractMaintainerActionHints } from './maintainer-analysis.js';
@@ -36,7 +36,7 @@ export async function assembleFetchedPR(signals, config, commitInfo) {
36
36
  const reviewDecision = determineReviewDecision(reviews);
37
37
  const mergeConflict = signals.hasMergeConflict;
38
38
  // Check if there's an unresponded maintainer comment (delegated to review-analysis module)
39
- const { hasUnrespondedComment, lastMaintainerComment } = checkUnrespondedComments(comments, reviews, reviewComments, config.githubUsername);
39
+ const { hasUnrespondedComment, lastMaintainerComment, unrespondedComments } = checkUnrespondedComments(comments, reviews, reviewComments, config.githubUsername);
40
40
  // Earliest maintainer response, computed from the comment/review timeline (#1461).
41
41
  const firstMaintainerResponseAt = getFirstMaintainerResponseAt(comments, reviews, config.githubUsername);
42
42
  // We need the commit date when hasUnrespondedComment is true (to distinguish
@@ -88,6 +88,10 @@ export async function assembleFetchedPR(signals, config, commitInfo) {
88
88
  contributorUsername: config.githubUsername,
89
89
  lastMaintainerCommentDate: lastMaintainerComment?.createdAt,
90
90
  latestChangesRequestedDate,
91
+ unansweredComments: unrespondedComments.map((c) => ({
92
+ createdAt: c.createdAt,
93
+ authorApprovalDate: getStandingApprovalDate(reviews, c.author),
94
+ })),
91
95
  hasActionableCIFailure,
92
96
  });
93
97
  const pr = {
@@ -43,6 +43,29 @@ export declare const CI_CONTEXTS_CAP = 100;
43
43
  * requested per PR. Only the newest non-contributor event matters for the
44
44
  * dormancy clock, so overflow is not routed to REST. */
45
45
  export declare const TIMELINE_CAP = 50;
46
+ /** Wait before the single re-query of PRs whose mergeability GitHub had not
47
+ * computed yet. The first query starts the computation; it usually lands
48
+ * within a couple of seconds. */
49
+ export declare const MERGEABLE_RETRY_DELAY_MS = 2000;
50
+ /**
51
+ * Fixed fragments of the log lines the open-PR fetch writes to stderr. The log
52
+ * sites and the tests that read stderr (#1941) share them, so rewording a
53
+ * message cannot silently blind a test.
54
+ */
55
+ export declare const PR_FETCH_LOG: {
56
+ /** Debug timing label, followed by ` <count> PRs`. */
57
+ readonly fetchDetails: "Fetch details for";
58
+ /** Debug suffix of the line logged for each PR enriched through REST. */
59
+ readonly restFallback: "(REST fallback)";
60
+ /** Warning: one batch query failed and its PRs went to REST. */
61
+ readonly batchFailed: "GraphQL batch failed";
62
+ /** Warning: the batch fetch threw (rate limit, auth) and every PR went to REST. */
63
+ readonly enrichmentFailed: "GraphQL batch enrichment failed";
64
+ /** Warning: one node could not be normalized and that PR went to REST. */
65
+ readonly normalizeFailed: "Failed to normalize";
66
+ /** Warning: a resolved PR could not be assembled and is reported as a failure. */
67
+ readonly assembleFailed: "Error assembling";
68
+ };
46
69
  /** A single PR to enrich. */
47
70
  export interface PRRef {
48
71
  owner: string;
@@ -63,7 +86,8 @@ export interface NormalizedPRData {
63
86
  body: string;
64
87
  createdAt: string;
65
88
  updatedAt: string;
66
- hasMergeConflict: boolean;
89
+ /** `null` when GitHub reported `UNKNOWN` (mergeability not computed yet). */
90
+ hasMergeConflict: boolean | null;
67
91
  headSha: string;
68
92
  comments: AssemblyComment[];
69
93
  reviews: AssemblyReview[];
@@ -108,6 +132,13 @@ interface GraphQLCheckRunNode {
108
132
  conclusion: string | null;
109
133
  status: string | null;
110
134
  startedAt: string | null;
135
+ checkSuite?: {
136
+ workflowRun: {
137
+ workflow: {
138
+ databaseId: number | null;
139
+ };
140
+ } | null;
141
+ } | null;
111
142
  }
112
143
  interface GraphQLStatusContextNode {
113
144
  __typename: 'StatusContext';
@@ -121,9 +152,11 @@ type GraphQLRollupContextNode = GraphQLCheckRunNode | GraphQLStatusContextNode |
121
152
  interface GraphQLCommitNode {
122
153
  oid: string;
123
154
  authoredDate: string | null;
155
+ committedDate: string | null;
124
156
  author: {
125
157
  user: GraphQLActor | null;
126
158
  } | null;
159
+ committer: GraphQLGitActor;
127
160
  status: {
128
161
  state: string;
129
162
  contexts: Array<{
@@ -237,8 +270,9 @@ export declare function isGraphqlRateLimited(err: unknown): boolean;
237
270
  * Enrich a set of PRs via batched GraphQL queries.
238
271
  *
239
272
  * Returns the PRs that resolved cleanly plus the URLs that must fall back to the
240
- * REST enrichment path. Batches run sequentially (GitHub recommends serial
241
- * requests); with ~3 queries for 30 PRs there is no concurrency benefit.
273
+ * REST enrichment path. PRs whose mergeability GitHub had not computed yet
274
+ * (`UNKNOWN`) are re-queried once after {@link MERGEABLE_RETRY_DELAY_MS}; one
275
+ * still unknown keeps `hasMergeConflict: null` for the caller to resolve.
242
276
  */
243
277
  export declare function batchFetchPRDetails(octokit: Octokit, refs: PRRef[]): Promise<BatchPRResult>;
244
278
  export {};
@@ -23,8 +23,10 @@
23
23
  * - A missing / inaccessible / malformed PR node → REST.
24
24
  */
25
25
  import { computeCIStatus } from './ci-analysis.js';
26
+ import { commitDateOf } from './commit-date.js';
26
27
  import { isRateLimitOrAuthError, errorMessage } from './errors.js';
27
28
  import { warn } from './logger.js';
29
+ import { sleep } from './concurrency.js';
28
30
  const MODULE = 'pr-graphql';
29
31
  /** PRs per aliased GraphQL query. GitHub recommends modest batch sizes; ~10 keeps
30
32
  * each query cheap (~1 point) and well under node/complexity limits. */
@@ -43,6 +45,29 @@ export const CI_CONTEXTS_CAP = 100;
43
45
  * requested per PR. Only the newest non-contributor event matters for the
44
46
  * dormancy clock, so overflow is not routed to REST. */
45
47
  export const TIMELINE_CAP = 50;
48
+ /** Wait before the single re-query of PRs whose mergeability GitHub had not
49
+ * computed yet. The first query starts the computation; it usually lands
50
+ * within a couple of seconds. */
51
+ export const MERGEABLE_RETRY_DELAY_MS = 2000;
52
+ /**
53
+ * Fixed fragments of the log lines the open-PR fetch writes to stderr. The log
54
+ * sites and the tests that read stderr (#1941) share them, so rewording a
55
+ * message cannot silently blind a test.
56
+ */
57
+ export const PR_FETCH_LOG = {
58
+ /** Debug timing label, followed by ` <count> PRs`. */
59
+ fetchDetails: 'Fetch details for',
60
+ /** Debug suffix of the line logged for each PR enriched through REST. */
61
+ restFallback: '(REST fallback)',
62
+ /** Warning: one batch query failed and its PRs went to REST. */
63
+ batchFailed: 'GraphQL batch failed',
64
+ /** Warning: the batch fetch threw (rate limit, auth) and every PR went to REST. */
65
+ enrichmentFailed: 'GraphQL batch enrichment failed',
66
+ /** Warning: one node could not be normalized and that PR went to REST. */
67
+ normalizeFailed: 'Failed to normalize',
68
+ /** Warning: a resolved PR could not be assembled and is reported as a failure. */
69
+ assembleFailed: 'Error assembling',
70
+ };
46
71
  /**
47
72
  * GraphQL reports a GitHub App as `__typename: 'Bot'` with a bare login, where
48
73
  * REST reports the same account as `login: 'name[bot]'`. Restore the REST spelling
@@ -125,14 +150,16 @@ const PR_FIELDS = `
125
150
  commit {
126
151
  oid
127
152
  authoredDate
153
+ committedDate
128
154
  author { user { login } }
155
+ committer { user { login } }
129
156
  status { state contexts { context state description } }
130
157
  statusCheckRollup {
131
158
  contexts(first: ${CI_CONTEXTS_CAP}) {
132
159
  totalCount
133
160
  nodes {
134
161
  __typename
135
- ... on CheckRun { name conclusion status startedAt }
162
+ ... on CheckRun { name conclusion status startedAt checkSuite { workflowRun { workflow { databaseId } } } }
136
163
  ... on StatusContext { context state description }
137
164
  }
138
165
  }
@@ -160,10 +187,13 @@ export function buildBatchQuery(refs) {
160
187
  const query = `query batchPRDetails(${varDefs.join(', ')}) {\n${selections.join('\n')}\n}`;
161
188
  return { query, variables };
162
189
  }
163
- /** Map GraphQL `mergeable` enum to the REST `mergeConflict` boolean. */
190
+ /** Map GraphQL `mergeable` enum to the REST `mergeConflict` value. */
164
191
  function toMergeConflict(mergeable) {
165
192
  // CONFLICTING mirrors REST `mergeable === false` / `mergeable_state === 'dirty'`.
166
- // UNKNOWN mirrors REST `mergeable === null` (GitHub hasn't computed it yet) → not a conflict.
193
+ // UNKNOWN mirrors REST `mergeable === null` (GitHub hasn't computed it yet):
194
+ // neither clean nor conflicted, so it stays `null` for the caller to resolve.
195
+ if (mergeable === 'UNKNOWN')
196
+ return null;
167
197
  return mergeable === 'CONFLICTING';
168
198
  }
169
199
  /** Map a GraphQL commit's rollup + legacy status into the CI result via the shared computer. */
@@ -177,6 +207,9 @@ function toCIStatus(commit) {
177
207
  conclusion: n.conclusion ? n.conclusion.toLowerCase() : null,
178
208
  status: (n.status ?? '').toLowerCase(),
179
209
  started_at: n.startedAt ?? null,
210
+ // `Workflow.databaseId` is the same id as REST `workflow_id`, so both
211
+ // transports dedupe on an identical workflow id + job name key (#1917).
212
+ workflowId: n.checkSuite?.workflowRun?.workflow.databaseId ?? null,
180
213
  }));
181
214
  // Combined statuses come from the legacy status object (mirrors
182
215
  // `repos.getCombinedStatusForRef`). When absent, an empty statuses list is
@@ -240,7 +273,12 @@ export function normalizePRNode(node) {
240
273
  })));
241
274
  const commit = node.commits.nodes[0]?.commit;
242
275
  const commitInfo = {
243
- date: commit?.authoredDate ?? undefined,
276
+ date: commitDateOf({
277
+ authorDate: commit?.authoredDate,
278
+ committerDate: commit?.committedDate,
279
+ authorLogin: commit?.author?.user?.login,
280
+ committerLogin: commit?.committer?.user?.login,
281
+ }),
244
282
  author: commit?.author?.user?.login ?? undefined,
245
283
  };
246
284
  return {
@@ -302,7 +340,7 @@ async function runBatch(octokit, refs) {
302
340
  const partial = err.data;
303
341
  if (partial)
304
342
  return partial;
305
- warn(MODULE, `GraphQL batch failed, falling back to REST: ${errorMessage(err)}`);
343
+ warn(MODULE, `${PR_FETCH_LOG.batchFailed}, falling back to REST: ${errorMessage(err)}`);
306
344
  return null;
307
345
  }
308
346
  }
@@ -310,19 +348,42 @@ async function runBatch(octokit, refs) {
310
348
  * Enrich a set of PRs via batched GraphQL queries.
311
349
  *
312
350
  * Returns the PRs that resolved cleanly plus the URLs that must fall back to the
313
- * REST enrichment path. Batches run sequentially (GitHub recommends serial
314
- * requests); with ~3 queries for 30 PRs there is no concurrency benefit.
351
+ * REST enrichment path. PRs whose mergeability GitHub had not computed yet
352
+ * (`UNKNOWN`) are re-queried once after {@link MERGEABLE_RETRY_DELAY_MS}; one
353
+ * still unknown keeps `hasMergeConflict: null` for the caller to resolve.
315
354
  */
316
355
  export async function batchFetchPRDetails(octokit, refs) {
317
- const resolved = new Map();
318
- const restFallbackUrls = [];
319
356
  if (refs.length === 0)
320
- return { resolved, restFallbackUrls };
357
+ return { resolved: new Map(), restFallbackUrls: [] };
321
358
  // No GraphQL client available (e.g. a stubbed Octokit in tests) — everything
322
359
  // to REST. Guards against calling a non-function `.graphql`.
323
360
  if (typeof octokit.graphql !== 'function') {
324
- return { resolved, restFallbackUrls: refs.map((r) => r.url) };
361
+ return { resolved: new Map(), restFallbackUrls: refs.map((r) => r.url) };
325
362
  }
363
+ const result = await fetchBatches(octokit, refs);
364
+ const unknown = refs.filter((r) => result.resolved.get(r.url)?.hasMergeConflict === null);
365
+ if (unknown.length > 0) {
366
+ await sleep(MERGEABLE_RETRY_DELAY_MS);
367
+ try {
368
+ // Only a clean re-resolve replaces the first answer; a PR the retry could
369
+ // not resolve keeps its first-pass data instead of moving to REST.
370
+ const retry = await fetchBatches(octokit, unknown);
371
+ for (const [url, data] of retry.resolved)
372
+ result.resolved.set(url, data);
373
+ }
374
+ catch (err) {
375
+ // The first pass already succeeded, so a failed re-query (even a rate
376
+ // limit) costs only the mergeability answer, not the whole run.
377
+ warn(MODULE, `Mergeability re-query failed, keeping first-pass data: ${errorMessage(err)}`);
378
+ }
379
+ }
380
+ return result;
381
+ }
382
+ /** Run the batches sequentially (GitHub recommends serial requests); with ~3
383
+ * queries for 30 PRs there is no concurrency benefit. */
384
+ async function fetchBatches(octokit, refs) {
385
+ const resolved = new Map();
386
+ const restFallbackUrls = [];
326
387
  for (const batch of chunk(refs, BATCH_SIZE)) {
327
388
  const data = await runBatch(octokit, batch);
328
389
  if (!data) {
@@ -340,7 +401,7 @@ export async function batchFetchPRDetails(octokit, refs) {
340
401
  outcome = normalizePRNode(data[`pr${i}`]?.pullRequest);
341
402
  }
342
403
  catch (err) {
343
- warn(MODULE, `Failed to normalize ${ref.url}, falling back to REST: ${errorMessage(err)}`);
404
+ warn(MODULE, `${PR_FETCH_LOG.normalizeFailed} ${ref.url}, falling back to REST: ${errorMessage(err)}`);
344
405
  outcome = { kind: 'missing' };
345
406
  }
346
407
  if (outcome.kind === 'ok') {
@@ -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,7 +126,7 @@ 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.
@@ -136,19 +154,17 @@ export declare class PRMonitor {
136
154
  */
137
155
  fetchUserClosedPRCounts(starFilter?: StarFilter): Promise<PRCountsResult<number>>;
138
156
  /**
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.
157
+ * Fetch metadata (star count, primary language, visibility) for a list of repositories.
158
+ * All fields come from the same `repos.get()` call — zero additional API cost.
141
159
  */
142
- fetchRepoMetadata(repos: string[]): Promise<Map<string, {
143
- stars: number;
144
- language: string | null;
145
- }>>;
160
+ fetchRepoMetadata(repos: string[]): Promise<Map<string, RepoMetadata>>;
146
161
  /**
147
162
  * Fetch PRs closed without merge in the last N days.
148
163
  * @param days - Lookback window in days (default: 7)
164
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
149
165
  * @returns Recently closed PRs
150
166
  */
151
- fetchRecentlyClosedPRs(days?: number): Promise<ClosedPR[]>;
167
+ fetchRecentlyClosedPRs(days?: number, truncations?: RecentListTruncation[]): Promise<ClosedPR[]>;
152
168
  /**
153
169
  * Login of the account that closed a PR (#1863), or undefined when GitHub
154
170
  * reports none. The Search API items behind `fetchRecentlyClosedPRs` carry
@@ -163,9 +179,10 @@ export declare class PRMonitor {
163
179
  /**
164
180
  * Fetch PRs merged in the last N days.
165
181
  * @param days - Lookback window in days (default: 7)
182
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
166
183
  * @returns Recently merged PRs
167
184
  */
168
- fetchRecentlyMergedPRs(days?: number): Promise<MergedPR[]>;
185
+ fetchRecentlyMergedPRs(days?: number, truncations?: RecentListTruncation[]): Promise<MergedPR[]>;
169
186
  /**
170
187
  * Everything the merged-PR notes selection reads for one PR (#1861): issue
171
188
  * comments, reviews, inline review comments and commits, each paginated.
@@ -14,16 +14,17 @@
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
24
  import { fetchCompareStatus as fetchCompareStatusImpl, fetchReviewedOpenPRs as fetchReviewedOpenPRsImpl, fetchReviewedPRActivity as fetchReviewedPRActivityImpl, } from './reviewed-prs-fetch.js';
25
+ import { commitDateOf } from './commit-date.js';
25
26
  import { assembleFetchedPR } from './pr-assembly.js';
26
- import { batchFetchPRDetails } from './pr-graphql.js';
27
+ import { batchFetchPRDetails, MERGEABLE_RETRY_DELAY_MS, PR_FETCH_LOG, } from './pr-graphql.js';
27
28
  import { fetchUserMergedPRCounts as fetchUserMergedPRCountsImpl, fetchUserClosedPRCounts as fetchUserClosedPRCountsImpl, fetchRecentlyClosedPRs as fetchRecentlyClosedPRsImpl, fetchRecentlyMergedPRs as fetchRecentlyMergedPRsImpl, } from './github-stats.js';
28
29
  import { isPlaceholderUsername } from './placeholder-usernames.js';
29
30
  // Re-export so existing consumers can still import from pr-monitor
@@ -33,13 +34,16 @@ export { isConditionalChecklistItem } from './checklist-analysis.js';
33
34
  export { determineStatus } from './status-determination.js';
34
35
  /**
35
36
  * 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'.
37
+ * Returns true when mergeable is explicitly false or the mergeable_state is 'dirty',
38
+ * and null when GitHub has not computed mergeability yet (neither clean nor conflicted).
37
39
  *
38
40
  * @param mergeable - GitHub's mergeable flag (null when not yet computed)
39
41
  * @param mergeableState - GitHub's mergeable_state string
40
42
  */
41
43
  export function hasMergeConflict(mergeable, mergeableState) {
42
- return mergeable === false || mergeableState === 'dirty';
44
+ if (mergeable === false || mergeableState === 'dirty')
45
+ return true;
46
+ return mergeable === null ? null : false;
43
47
  }
44
48
  const MODULE = 'pr-monitor';
45
49
  const MAX_CONCURRENT_REQUESTS = DEFAULT_CONCURRENCY;
@@ -259,7 +263,7 @@ export class PRMonitor {
259
263
  // the common case in a handful of ~1-point queries; anything it can't resolve
260
264
  // (connection cap overflow, missing node, GraphQL outage) falls back to the
261
265
  // per-PR REST path via the worker pool.
262
- await timed('pr-monitor', `Fetch details for ${refs.length} PRs`, async () => {
266
+ await timed('pr-monitor', `${PR_FETCH_LOG.fetchDetails} ${refs.length} PRs`, async () => {
263
267
  let batch;
264
268
  try {
265
269
  batch = await batchFetchPRDetails(this.octokit, refs);
@@ -268,7 +272,7 @@ export class PRMonitor {
268
272
  // A fatal batch-level GraphQL error (rate limit / auth). Don't crash the
269
273
  // run — route every PR to the REST path, which surfaces per-PR failures
270
274
  // exactly as the pre-GraphQL implementation did.
271
- warn(MODULE, `GraphQL batch enrichment failed (${errorMessage(error)}); falling back to REST for all PRs`);
275
+ warn(MODULE, `${PR_FETCH_LOG.enrichmentFailed} (${errorMessage(error)}); falling back to REST for all PRs`);
272
276
  batch = { resolved: new Map(), restFallbackUrls: refs.map((r) => r.url) };
273
277
  }
274
278
  // Assemble GraphQL-resolved PRs (no additional network calls).
@@ -281,14 +285,14 @@ export class PRMonitor {
281
285
  }
282
286
  catch (error) {
283
287
  const errMsg = errorMessage(error);
284
- warn('pr-monitor', `Error assembling ${url}: ${errMsg}`);
288
+ warn('pr-monitor', `${PR_FETCH_LOG.assembleFailed} ${url}: ${errMsg}`);
285
289
  failures.push({ prUrl: url, error: errMsg });
286
290
  }
287
291
  }
288
292
  // REST fallback for the remainder, using a worker pool for bounded concurrency.
289
293
  await runWorkerPool(batch.restFallbackUrls, async (url) => {
290
294
  try {
291
- debug('pr-monitor', `Fetching details for ${url} (REST fallback)`);
295
+ debug('pr-monitor', `Fetching details for ${url} ${PR_FETCH_LOG.restFallback}`);
292
296
  const pr = await this.fetchPRDetails(url, warnings);
293
297
  if (pr)
294
298
  prs.push(pr);
@@ -353,6 +357,7 @@ export class PRMonitor {
353
357
  }
354
358
  // Non-rate-limit 403 (DMCA, private repo, SSO) — degrade gracefully
355
359
  warn('pr-monitor', `403 fetching review comments for ${owner}/${repo}#${number}: ${msg}`);
360
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- pins the Promise.all element type for the fallback branch
356
361
  return { items: [], truncated: false };
357
362
  }
358
363
  if (status === 404) {
@@ -361,6 +366,7 @@ export class PRMonitor {
361
366
  else {
362
367
  warn('pr-monitor', `Failed to fetch review comments for ${owner}/${repo}#${number} (status ${status ?? 'unknown'}): self-reply detection will be skipped`);
363
368
  }
369
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- pins the Promise.all element type for the fallback branch
364
370
  return { items: [], truncated: false };
365
371
  }),
366
372
  ]);
@@ -378,6 +384,21 @@ export class PRMonitor {
378
384
  }
379
385
  const ghPR = prResponse.data;
380
386
  const reviews = reviewsResult.items;
387
+ // GitHub computes mergeability lazily: the first `pulls.get` starts the job
388
+ // and can answer null. Ask once more after a short delay (#1915).
389
+ let mergeConflict = hasMergeConflict(ghPR.mergeable, ghPR.mergeable_state);
390
+ if (mergeConflict === null) {
391
+ await sleep(MERGEABLE_RETRY_DELAY_MS);
392
+ try {
393
+ const { data } = await this.octokit.pulls.get({ owner, repo, pull_number: number });
394
+ mergeConflict = hasMergeConflict(data.mergeable, data.mergeable_state);
395
+ }
396
+ catch (err) {
397
+ if (isRateLimitOrAuthError(err))
398
+ throw err;
399
+ warn(MODULE, `Mergeability re-query failed for ${owner}/${repo}#${number}: ${errorMessage(err)}`);
400
+ }
401
+ }
381
402
  const activityEvents = await this.fetchActivityEvents(owner, repo, number);
382
403
  const ciStatus = await getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
383
404
  // The commit date is only consulted (and only fetched) when the PR has an
@@ -385,7 +406,7 @@ export class PRMonitor {
385
406
  // pipeline decides via `needCommitDate` and invokes this thunk lazily.
386
407
  // A PR with a status override is the exception: override auto-clear keys
387
408
  // on the commit date (#1713), so fetch it up front for those PRs only.
388
- const commitInfo = config.statusOverrides?.[prUrl]
409
+ const commitInfo = findRefKey(config.statusOverrides, prUrl)
389
410
  ? await this.fetchCommitInfo(owner, repo, ghPR.head.sha)
390
411
  : () => this.fetchCommitInfo(owner, repo, ghPR.head.sha);
391
412
  return assembleFetchedPR({
@@ -398,7 +419,7 @@ export class PRMonitor {
398
419
  body: ghPR.body || '',
399
420
  createdAt: ghPR.created_at,
400
421
  updatedAt: ghPR.updated_at,
401
- hasMergeConflict: hasMergeConflict(ghPR.mergeable, ghPR.mergeable_state),
422
+ hasMergeConflict: this.resolveMergeConflict(prUrl, mergeConflict),
402
423
  comments,
403
424
  reviews,
404
425
  reviewComments,
@@ -406,6 +427,19 @@ export class PRMonitor {
406
427
  ciStatus,
407
428
  }, config, commitInfo);
408
429
  }
430
+ /**
431
+ * Settle a merge-conflict answer GitHub left unknown after the re-query by
432
+ * reusing the previous run's value, so a known conflict is not hidden behind
433
+ * a waiting status for a run (#1915). No previous value means no conflict.
434
+ */
435
+ resolveMergeConflict(prUrl, fresh) {
436
+ if (fresh !== null)
437
+ return fresh;
438
+ const previous = this.stateManager.getState().lastDigest?.openPRs.find((pr) => pr.url === prUrl);
439
+ const wasConflicted = previous?.hasMergeConflict ?? false;
440
+ warn(MODULE, `Mergeability still unknown for ${prUrl}; assuming conflict=${wasConflicted} from the previous run`);
441
+ return wasConflicted;
442
+ }
409
443
  /**
410
444
  * REST counterpart of the GraphQL `timelineItems` selection: commits (author
411
445
  * and committer) plus force-push / review-request / label events, used for
@@ -429,7 +463,7 @@ export class PRMonitor {
429
463
  }
430
464
  }
431
465
  /**
432
- * Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
466
+ * Fetch the HEAD commit's date (see {@link commitDateOf}) and author login via REST `repos.getCommit`.
433
467
  * Rate-limit errors propagate (silently swallowing them produces misleading
434
468
  * status, e.g. needs_changes when changes were addressed) (#469); other
435
469
  * failures degrade to `undefined` so the PR is still returned.
@@ -438,7 +472,12 @@ export class PRMonitor {
438
472
  try {
439
473
  const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
440
474
  return {
441
- date: res.data.commit.author?.date,
475
+ date: commitDateOf({
476
+ authorDate: res.data.commit.author?.date,
477
+ committerDate: res.data.commit.committer?.date,
478
+ authorLogin: res.data.author?.login,
479
+ committerLogin: res.data.committer?.login,
480
+ }),
442
481
  // GitHub user login of the commit author (may differ from git author)
443
482
  author: res.data.author?.login,
444
483
  };
@@ -476,7 +515,7 @@ export class PRMonitor {
476
515
  body: data.body,
477
516
  createdAt: data.createdAt,
478
517
  updatedAt: data.updatedAt,
479
- hasMergeConflict: data.hasMergeConflict,
518
+ hasMergeConflict: this.resolveMergeConflict(ref.url, data.hasMergeConflict),
480
519
  comments: data.comments,
481
520
  reviews: data.reviews,
482
521
  reviewComments: data.reviewComments,
@@ -491,7 +530,7 @@ export class PRMonitor {
491
530
  */
492
531
  async fetchUserMergedPRCounts(starFilter) {
493
532
  const config = this.stateManager.getState().config;
494
- return fetchUserMergedPRCountsImpl(this.octokit, config.githubUsername, starFilter);
533
+ return fetchUserMergedPRCountsImpl(this.octokit, config.githubUsername, starFilter, config.untrackedOrgs);
495
534
  }
496
535
  /**
497
536
  * Fetch closed-without-merge PR counts per repository for the configured user.
@@ -500,11 +539,11 @@ export class PRMonitor {
500
539
  */
501
540
  async fetchUserClosedPRCounts(starFilter) {
502
541
  const config = this.stateManager.getState().config;
503
- return fetchUserClosedPRCountsImpl(this.octokit, config.githubUsername, starFilter);
542
+ return fetchUserClosedPRCountsImpl(this.octokit, config.githubUsername, starFilter, config.untrackedOrgs);
504
543
  }
505
544
  /**
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.
545
+ * Fetch metadata (star count, primary language, visibility) for a list of repositories.
546
+ * All fields come from the same `repos.get()` call — zero additional API cost.
508
547
  */
509
548
  async fetchRepoMetadata(repos) {
510
549
  if (repos.length === 0)
@@ -530,7 +569,14 @@ export class PRMonitor {
530
569
  repo: name,
531
570
  headers,
532
571
  }));
533
- const metadata = { stars: data.stargazers_count, language: data.language ?? null };
572
+ const metadata = {
573
+ stars: data.stargazers_count,
574
+ language: data.language ?? null,
575
+ // The whole response body is what the ETag cache stores, so a 304
576
+ // answers from a body that carries the flag too. Anything but a
577
+ // boolean (an unexpected body) reads as unknown.
578
+ isPrivate: typeof data.private === 'boolean' ? data.private : undefined,
579
+ };
534
580
  return { repo, metadata };
535
581
  }));
536
582
  let chunkFailures = 0;
@@ -559,11 +605,12 @@ export class PRMonitor {
559
605
  /**
560
606
  * Fetch PRs closed without merge in the last N days.
561
607
  * @param days - Lookback window in days (default: 7)
608
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
562
609
  * @returns Recently closed PRs
563
610
  */
564
- async fetchRecentlyClosedPRs(days = 7) {
611
+ async fetchRecentlyClosedPRs(days = 7, truncations) {
565
612
  const config = this.stateManager.getState().config;
566
- return fetchRecentlyClosedPRsImpl(this.octokit, config, days);
613
+ return fetchRecentlyClosedPRsImpl(this.octokit, config, days, truncations);
567
614
  }
568
615
  /**
569
616
  * Login of the account that closed a PR (#1863), or undefined when GitHub
@@ -590,11 +637,12 @@ export class PRMonitor {
590
637
  /**
591
638
  * Fetch PRs merged in the last N days.
592
639
  * @param days - Lookback window in days (default: 7)
640
+ * @param truncations - Receives the recent-list truncation when the search returned a partial list (#1928)
593
641
  * @returns Recently merged PRs
594
642
  */
595
- async fetchRecentlyMergedPRs(days = 7) {
643
+ async fetchRecentlyMergedPRs(days = 7, truncations) {
596
644
  const config = this.stateManager.getState().config;
597
- return fetchRecentlyMergedPRsImpl(this.octokit, config, days);
645
+ return fetchRecentlyMergedPRsImpl(this.octokit, config, days, truncations);
598
646
  }
599
647
  /**
600
648
  * Everything the merged-PR notes selection reads for one PR (#1861): issue